limit.out 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. --
  2. -- LIMIT
  3. -- Check the LIMIT/OFFSET feature of SELECT
  4. --
  5. SELECT ''::text AS two, unique1, unique2, stringu1
  6. FROM onek WHERE unique1 > 50
  7. ORDER BY unique1 LIMIT 2;
  8. two | unique1 | unique2 | stringu1
  9. -----+---------+---------+----------
  10. | 51 | 76 | ZBAAAA
  11. | 52 | 985 | ACAAAA
  12. (2 rows)
  13. SELECT ''::text AS five, unique1, unique2, stringu1
  14. FROM onek WHERE unique1 > 60
  15. ORDER BY unique1 LIMIT 5;
  16. five | unique1 | unique2 | stringu1
  17. ------+---------+---------+----------
  18. | 61 | 560 | JCAAAA
  19. | 62 | 633 | KCAAAA
  20. | 63 | 296 | LCAAAA
  21. | 64 | 479 | MCAAAA
  22. | 65 | 64 | NCAAAA
  23. (5 rows)
  24. SELECT ''::text AS two, unique1, unique2, stringu1
  25. FROM onek WHERE unique1 > 60 AND unique1 < 63
  26. ORDER BY unique1 LIMIT 5;
  27. two | unique1 | unique2 | stringu1
  28. -----+---------+---------+----------
  29. | 61 | 560 | JCAAAA
  30. | 62 | 633 | KCAAAA
  31. (2 rows)
  32. SELECT ''::text AS three, unique1, unique2, stringu1
  33. FROM onek WHERE unique1 > 100
  34. ORDER BY unique1 LIMIT 3 OFFSET 20;
  35. three | unique1 | unique2 | stringu1
  36. -------+---------+---------+----------
  37. | 121 | 700 | REAAAA
  38. | 122 | 519 | SEAAAA
  39. | 123 | 777 | TEAAAA
  40. (3 rows)
  41. SELECT ''::text AS zero, unique1, unique2, stringu1
  42. FROM onek WHERE unique1 < 50
  43. ORDER BY unique1 DESC LIMIT 8 OFFSET 99;
  44. zero | unique1 | unique2 | stringu1
  45. ------+---------+---------+----------
  46. (0 rows)
  47. SELECT ''::text AS eleven, unique1, unique2, stringu1
  48. FROM onek WHERE unique1 < 50
  49. ORDER BY unique1 DESC LIMIT 20 OFFSET 39;
  50. eleven | unique1 | unique2 | stringu1
  51. --------+---------+---------+----------
  52. | 10 | 520 | KAAAAA
  53. | 9 | 49 | JAAAAA
  54. | 8 | 653 | IAAAAA
  55. | 7 | 647 | HAAAAA
  56. | 6 | 978 | GAAAAA
  57. | 5 | 541 | FAAAAA
  58. | 4 | 833 | EAAAAA
  59. | 3 | 431 | DAAAAA
  60. | 2 | 326 | CAAAAA
  61. | 1 | 214 | BAAAAA
  62. | 0 | 998 | AAAAAA
  63. (11 rows)
  64. SELECT ''::text AS ten, unique1, unique2, stringu1
  65. FROM onek
  66. ORDER BY unique1 OFFSET 990;
  67. ten | unique1 | unique2 | stringu1
  68. -----+---------+---------+----------
  69. | 990 | 369 | CMAAAA
  70. | 991 | 426 | DMAAAA
  71. | 992 | 363 | EMAAAA
  72. | 993 | 661 | FMAAAA
  73. | 994 | 695 | GMAAAA
  74. | 995 | 144 | HMAAAA
  75. | 996 | 258 | IMAAAA
  76. | 997 | 21 | JMAAAA
  77. | 998 | 549 | KMAAAA
  78. | 999 | 152 | LMAAAA
  79. (10 rows)
  80. SELECT ''::text AS five, unique1, unique2, stringu1
  81. FROM onek
  82. ORDER BY unique1 OFFSET 990 LIMIT 5;
  83. five | unique1 | unique2 | stringu1
  84. ------+---------+---------+----------
  85. | 990 | 369 | CMAAAA
  86. | 991 | 426 | DMAAAA
  87. | 992 | 363 | EMAAAA
  88. | 993 | 661 | FMAAAA
  89. | 994 | 695 | GMAAAA
  90. (5 rows)
  91. SELECT ''::text AS five, unique1, unique2, stringu1
  92. FROM onek
  93. ORDER BY unique1 LIMIT 5 OFFSET 900;
  94. five | unique1 | unique2 | stringu1
  95. ------+---------+---------+----------
  96. | 900 | 913 | QIAAAA
  97. | 901 | 931 | RIAAAA
  98. | 902 | 702 | SIAAAA
  99. | 903 | 641 | TIAAAA
  100. | 904 | 793 | UIAAAA
  101. (5 rows)
  102. -- Test null limit and offset. The planner would discard a simple null
  103. -- constant, so to ensure executor is exercised, do this:
  104. select * from int8_tbl limit (case when random() < 0.5 then null::bigint end);
  105. q1 | q2
  106. ------------------+-------------------
  107. 123 | 456
  108. 123 | 4567890123456789
  109. 4567890123456789 | 123
  110. 4567890123456789 | 4567890123456789
  111. 4567890123456789 | -4567890123456789
  112. (5 rows)
  113. select * from int8_tbl offset (case when random() < 0.5 then null::bigint end);
  114. q1 | q2
  115. ------------------+-------------------
  116. 123 | 456
  117. 123 | 4567890123456789
  118. 4567890123456789 | 123
  119. 4567890123456789 | 4567890123456789
  120. 4567890123456789 | -4567890123456789
  121. (5 rows)
  122. -- Test assorted cases involving backwards fetch from a LIMIT plan node
  123. begin;
  124. declare c1 cursor for select * from int8_tbl limit 10;
  125. fetch all in c1;
  126. q1 | q2
  127. ------------------+-------------------
  128. 123 | 456
  129. 123 | 4567890123456789
  130. 4567890123456789 | 123
  131. 4567890123456789 | 4567890123456789
  132. 4567890123456789 | -4567890123456789
  133. (5 rows)
  134. fetch 1 in c1;
  135. q1 | q2
  136. ----+----
  137. (0 rows)
  138. fetch backward 1 in c1;
  139. q1 | q2
  140. ------------------+-------------------
  141. 4567890123456789 | -4567890123456789
  142. (1 row)
  143. fetch backward all in c1;
  144. q1 | q2
  145. ------------------+------------------
  146. 4567890123456789 | 4567890123456789
  147. 4567890123456789 | 123
  148. 123 | 4567890123456789
  149. 123 | 456
  150. (4 rows)
  151. fetch backward 1 in c1;
  152. q1 | q2
  153. ----+----
  154. (0 rows)
  155. fetch all in c1;
  156. q1 | q2
  157. ------------------+-------------------
  158. 123 | 456
  159. 123 | 4567890123456789
  160. 4567890123456789 | 123
  161. 4567890123456789 | 4567890123456789
  162. 4567890123456789 | -4567890123456789
  163. (5 rows)
  164. declare c2 cursor for select * from int8_tbl limit 3;
  165. fetch all in c2;
  166. q1 | q2
  167. ------------------+------------------
  168. 123 | 456
  169. 123 | 4567890123456789
  170. 4567890123456789 | 123
  171. (3 rows)
  172. fetch 1 in c2;
  173. q1 | q2
  174. ----+----
  175. (0 rows)
  176. fetch backward 1 in c2;
  177. q1 | q2
  178. ------------------+-----
  179. 4567890123456789 | 123
  180. (1 row)
  181. fetch backward all in c2;
  182. q1 | q2
  183. -----+------------------
  184. 123 | 4567890123456789
  185. 123 | 456
  186. (2 rows)
  187. fetch backward 1 in c2;
  188. q1 | q2
  189. ----+----
  190. (0 rows)
  191. fetch all in c2;
  192. q1 | q2
  193. ------------------+------------------
  194. 123 | 456
  195. 123 | 4567890123456789
  196. 4567890123456789 | 123
  197. (3 rows)
  198. declare c3 cursor for select * from int8_tbl offset 3;
  199. fetch all in c3;
  200. q1 | q2
  201. ------------------+-------------------
  202. 4567890123456789 | 4567890123456789
  203. 4567890123456789 | -4567890123456789
  204. (2 rows)
  205. fetch 1 in c3;
  206. q1 | q2
  207. ----+----
  208. (0 rows)
  209. fetch backward 1 in c3;
  210. q1 | q2
  211. ------------------+-------------------
  212. 4567890123456789 | -4567890123456789
  213. (1 row)
  214. fetch backward all in c3;
  215. q1 | q2
  216. ------------------+------------------
  217. 4567890123456789 | 4567890123456789
  218. (1 row)
  219. fetch backward 1 in c3;
  220. q1 | q2
  221. ----+----
  222. (0 rows)
  223. fetch all in c3;
  224. q1 | q2
  225. ------------------+-------------------
  226. 4567890123456789 | 4567890123456789
  227. 4567890123456789 | -4567890123456789
  228. (2 rows)
  229. declare c4 cursor for select * from int8_tbl offset 10;
  230. fetch all in c4;
  231. q1 | q2
  232. ----+----
  233. (0 rows)
  234. fetch 1 in c4;
  235. q1 | q2
  236. ----+----
  237. (0 rows)
  238. fetch backward 1 in c4;
  239. q1 | q2
  240. ----+----
  241. (0 rows)
  242. fetch backward all in c4;
  243. q1 | q2
  244. ----+----
  245. (0 rows)
  246. fetch backward 1 in c4;
  247. q1 | q2
  248. ----+----
  249. (0 rows)
  250. fetch all in c4;
  251. q1 | q2
  252. ----+----
  253. (0 rows)
  254. declare c5 cursor for select * from int8_tbl order by q1 fetch first 2 rows with ties;
  255. fetch all in c5;
  256. q1 | q2
  257. -----+------------------
  258. 123 | 456
  259. 123 | 4567890123456789
  260. (2 rows)
  261. fetch 1 in c5;
  262. q1 | q2
  263. ----+----
  264. (0 rows)
  265. fetch backward 1 in c5;
  266. q1 | q2
  267. -----+------------------
  268. 123 | 4567890123456789
  269. (1 row)
  270. fetch backward 1 in c5;
  271. q1 | q2
  272. -----+-----
  273. 123 | 456
  274. (1 row)
  275. fetch all in c5;
  276. q1 | q2
  277. -----+------------------
  278. 123 | 4567890123456789
  279. (1 row)
  280. fetch backward all in c5;
  281. q1 | q2
  282. -----+------------------
  283. 123 | 4567890123456789
  284. 123 | 456
  285. (2 rows)
  286. fetch all in c5;
  287. q1 | q2
  288. -----+------------------
  289. 123 | 456
  290. 123 | 4567890123456789
  291. (2 rows)
  292. fetch backward all in c5;
  293. q1 | q2
  294. -----+------------------
  295. 123 | 4567890123456789
  296. 123 | 456
  297. (2 rows)
  298. rollback;
  299. -- Stress test for variable LIMIT in conjunction with bounded-heap sorting
  300. SELECT
  301. (SELECT n
  302. FROM (VALUES (1)) AS x,
  303. (SELECT n FROM generate_series(1,10) AS n
  304. ORDER BY n LIMIT 1 OFFSET s-1) AS y) AS z
  305. FROM generate_series(1,10) AS s;
  306. z
  307. ----
  308. 1
  309. 2
  310. 3
  311. 4
  312. 5
  313. 6
  314. 7
  315. 8
  316. 9
  317. 10
  318. (10 rows)
  319. --
  320. -- Test behavior of volatile and set-returning functions in conjunction
  321. -- with ORDER BY and LIMIT.
  322. --
  323. create temp sequence testseq;
  324. explain (verbose, costs off)
  325. select unique1, unique2, nextval('testseq')
  326. from tenk1 order by unique2 limit 10;
  327. QUERY PLAN
  328. ----------------------------------------------------------------
  329. Limit
  330. Output: unique1, unique2, (nextval('testseq'::regclass))
  331. -> Index Scan using tenk1_unique2 on public.tenk1
  332. Output: unique1, unique2, nextval('testseq'::regclass)
  333. (4 rows)
  334. select unique1, unique2, nextval('testseq')
  335. from tenk1 order by unique2 limit 10;
  336. unique1 | unique2 | nextval
  337. ---------+---------+---------
  338. 8800 | 0 | 1
  339. 1891 | 1 | 2
  340. 3420 | 2 | 3
  341. 9850 | 3 | 4
  342. 7164 | 4 | 5
  343. 8009 | 5 | 6
  344. 5057 | 6 | 7
  345. 6701 | 7 | 8
  346. 4321 | 8 | 9
  347. 3043 | 9 | 10
  348. (10 rows)
  349. select currval('testseq');
  350. currval
  351. ---------
  352. 10
  353. (1 row)
  354. explain (verbose, costs off)
  355. select unique1, unique2, nextval('testseq')
  356. from tenk1 order by tenthous limit 10;
  357. QUERY PLAN
  358. --------------------------------------------------------------------------
  359. Limit
  360. Output: unique1, unique2, (nextval('testseq'::regclass)), tenthous
  361. -> Result
  362. Output: unique1, unique2, nextval('testseq'::regclass), tenthous
  363. -> Sort
  364. Output: unique1, unique2, tenthous
  365. Sort Key: tenk1.tenthous
  366. -> Seq Scan on public.tenk1
  367. Output: unique1, unique2, tenthous
  368. (9 rows)
  369. select unique1, unique2, nextval('testseq')
  370. from tenk1 order by tenthous limit 10;
  371. unique1 | unique2 | nextval
  372. ---------+---------+---------
  373. 0 | 9998 | 11
  374. 1 | 2838 | 12
  375. 2 | 2716 | 13
  376. 3 | 5679 | 14
  377. 4 | 1621 | 15
  378. 5 | 5557 | 16
  379. 6 | 2855 | 17
  380. 7 | 8518 | 18
  381. 8 | 5435 | 19
  382. 9 | 4463 | 20
  383. (10 rows)
  384. select currval('testseq');
  385. currval
  386. ---------
  387. 20
  388. (1 row)
  389. explain (verbose, costs off)
  390. select unique1, unique2, generate_series(1,10)
  391. from tenk1 order by unique2 limit 7;
  392. QUERY PLAN
  393. -------------------------------------------------------------------------------------------------------------------------------------------------------------
  394. Limit
  395. Output: unique1, unique2, (generate_series(1, 10))
  396. -> ProjectSet
  397. Output: unique1, unique2, generate_series(1, 10)
  398. -> Index Scan using tenk1_unique2 on public.tenk1
  399. Output: unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even, stringu1, stringu2, string4
  400. (6 rows)
  401. select unique1, unique2, generate_series(1,10)
  402. from tenk1 order by unique2 limit 7;
  403. unique1 | unique2 | generate_series
  404. ---------+---------+-----------------
  405. 8800 | 0 | 1
  406. 8800 | 0 | 2
  407. 8800 | 0 | 3
  408. 8800 | 0 | 4
  409. 8800 | 0 | 5
  410. 8800 | 0 | 6
  411. 8800 | 0 | 7
  412. (7 rows)
  413. explain (verbose, costs off)
  414. select unique1, unique2, generate_series(1,10)
  415. from tenk1 order by tenthous limit 7;
  416. QUERY PLAN
  417. --------------------------------------------------------------------
  418. Limit
  419. Output: unique1, unique2, (generate_series(1, 10)), tenthous
  420. -> ProjectSet
  421. Output: unique1, unique2, generate_series(1, 10), tenthous
  422. -> Sort
  423. Output: unique1, unique2, tenthous
  424. Sort Key: tenk1.tenthous
  425. -> Seq Scan on public.tenk1
  426. Output: unique1, unique2, tenthous
  427. (9 rows)
  428. select unique1, unique2, generate_series(1,10)
  429. from tenk1 order by tenthous limit 7;
  430. unique1 | unique2 | generate_series
  431. ---------+---------+-----------------
  432. 0 | 9998 | 1
  433. 0 | 9998 | 2
  434. 0 | 9998 | 3
  435. 0 | 9998 | 4
  436. 0 | 9998 | 5
  437. 0 | 9998 | 6
  438. 0 | 9998 | 7
  439. (7 rows)
  440. -- use of random() is to keep planner from folding the expressions together
  441. explain (verbose, costs off)
  442. select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
  443. QUERY PLAN
  444. ------------------------------------------------------------------------------------------------------
  445. ProjectSet
  446. Output: generate_series(0, 2), generate_series(((random() * '0.1'::double precision))::integer, 2)
  447. -> Result
  448. (3 rows)
  449. select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
  450. s1 | s2
  451. ----+----
  452. 0 | 0
  453. 1 | 1
  454. 2 | 2
  455. (3 rows)
  456. explain (verbose, costs off)
  457. select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2
  458. order by s2 desc;
  459. QUERY PLAN
  460. ------------------------------------------------------------------------------------------------------------
  461. Sort
  462. Output: (generate_series(0, 2)), (generate_series(((random() * '0.1'::double precision))::integer, 2))
  463. Sort Key: (generate_series(((random() * '0.1'::double precision))::integer, 2)) DESC
  464. -> ProjectSet
  465. Output: generate_series(0, 2), generate_series(((random() * '0.1'::double precision))::integer, 2)
  466. -> Result
  467. (6 rows)
  468. select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2
  469. order by s2 desc;
  470. s1 | s2
  471. ----+----
  472. 2 | 2
  473. 1 | 1
  474. 0 | 0
  475. (3 rows)
  476. -- test for failure to set all aggregates' aggtranstype
  477. explain (verbose, costs off)
  478. select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
  479. from tenk1 group by thousand order by thousand limit 3;
  480. QUERY PLAN
  481. -------------------------------------------------------------------------------------------------------------------
  482. Limit
  483. Output: (sum(tenthous)), (((sum(tenthous))::double precision + (random() * '0'::double precision))), thousand
  484. -> GroupAggregate
  485. Output: sum(tenthous), ((sum(tenthous))::double precision + (random() * '0'::double precision)), thousand
  486. Group Key: tenk1.thousand
  487. -> Index Only Scan using tenk1_thous_tenthous on public.tenk1
  488. Output: thousand, tenthous
  489. (7 rows)
  490. select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
  491. from tenk1 group by thousand order by thousand limit 3;
  492. s1 | s2
  493. -------+-------
  494. 45000 | 45000
  495. 45010 | 45010
  496. 45020 | 45020
  497. (3 rows)
  498. --
  499. -- FETCH FIRST
  500. -- Check the WITH TIES clause
  501. --
  502. SELECT thousand
  503. FROM onek WHERE thousand < 5
  504. ORDER BY thousand FETCH FIRST 2 ROW WITH TIES;
  505. thousand
  506. ----------
  507. 0
  508. 0
  509. 0
  510. 0
  511. 0
  512. 0
  513. 0
  514. 0
  515. 0
  516. 0
  517. (10 rows)
  518. SELECT thousand
  519. FROM onek WHERE thousand < 5
  520. ORDER BY thousand FETCH FIRST ROWS WITH TIES;
  521. thousand
  522. ----------
  523. 0
  524. 0
  525. 0
  526. 0
  527. 0
  528. 0
  529. 0
  530. 0
  531. 0
  532. 0
  533. (10 rows)
  534. SELECT thousand
  535. FROM onek WHERE thousand < 5
  536. ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;
  537. thousand
  538. ----------
  539. 0
  540. 0
  541. 0
  542. 0
  543. 0
  544. 0
  545. 0
  546. 0
  547. 0
  548. 0
  549. (10 rows)
  550. SELECT thousand
  551. FROM onek WHERE thousand < 5
  552. ORDER BY thousand FETCH FIRST 2 ROW ONLY;
  553. thousand
  554. ----------
  555. 0
  556. 0
  557. (2 rows)
  558. -- SKIP LOCKED and WITH TIES are incompatible
  559. SELECT thousand
  560. FROM onek WHERE thousand < 5
  561. ORDER BY thousand FETCH FIRST 1 ROW WITH TIES FOR UPDATE SKIP LOCKED;
  562. ERROR: SKIP LOCKED and WITH TIES options cannot be used together
  563. -- should fail
  564. SELECT ''::text AS two, unique1, unique2, stringu1
  565. FROM onek WHERE unique1 > 50
  566. FETCH FIRST 2 ROW WITH TIES;
  567. ERROR: WITH TIES cannot be specified without ORDER BY clause
  568. -- test ruleutils
  569. CREATE VIEW limit_thousand_v_1 AS SELECT thousand FROM onek WHERE thousand < 995
  570. ORDER BY thousand FETCH FIRST 5 ROWS WITH TIES OFFSET 10;
  571. \d+ limit_thousand_v_1
  572. View "public.limit_thousand_v_1"
  573. Column | Type | Collation | Nullable | Default | Storage | Description
  574. ----------+---------+-----------+----------+---------+---------+-------------
  575. thousand | integer | | | | plain |
  576. View definition:
  577. SELECT onek.thousand
  578. FROM onek
  579. WHERE onek.thousand < 995
  580. ORDER BY onek.thousand
  581. OFFSET 10
  582. FETCH FIRST 5 ROWS WITH TIES;
  583. CREATE VIEW limit_thousand_v_2 AS SELECT thousand FROM onek WHERE thousand < 995
  584. ORDER BY thousand OFFSET 10 FETCH FIRST 5 ROWS ONLY;
  585. \d+ limit_thousand_v_2
  586. View "public.limit_thousand_v_2"
  587. Column | Type | Collation | Nullable | Default | Storage | Description
  588. ----------+---------+-----------+----------+---------+---------+-------------
  589. thousand | integer | | | | plain |
  590. View definition:
  591. SELECT onek.thousand
  592. FROM onek
  593. WHERE onek.thousand < 995
  594. ORDER BY onek.thousand
  595. OFFSET 10
  596. LIMIT 5;
  597. CREATE VIEW limit_thousand_v_3 AS SELECT thousand FROM onek WHERE thousand < 995
  598. ORDER BY thousand FETCH FIRST NULL ROWS WITH TIES; -- fails
  599. ERROR: row count cannot be null in FETCH FIRST ... WITH TIES clause
  600. CREATE VIEW limit_thousand_v_3 AS SELECT thousand FROM onek WHERE thousand < 995
  601. ORDER BY thousand FETCH FIRST (NULL+1) ROWS WITH TIES;
  602. \d+ limit_thousand_v_3
  603. View "public.limit_thousand_v_3"
  604. Column | Type | Collation | Nullable | Default | Storage | Description
  605. ----------+---------+-----------+----------+---------+---------+-------------
  606. thousand | integer | | | | plain |
  607. View definition:
  608. SELECT onek.thousand
  609. FROM onek
  610. WHERE onek.thousand < 995
  611. ORDER BY onek.thousand
  612. FETCH FIRST (NULL::integer + 1) ROWS WITH TIES;
  613. CREATE VIEW limit_thousand_v_4 AS SELECT thousand FROM onek WHERE thousand < 995
  614. ORDER BY thousand FETCH FIRST NULL ROWS ONLY;
  615. \d+ limit_thousand_v_4
  616. View "public.limit_thousand_v_4"
  617. Column | Type | Collation | Nullable | Default | Storage | Description
  618. ----------+---------+-----------+----------+---------+---------+-------------
  619. thousand | integer | | | | plain |
  620. View definition:
  621. SELECT onek.thousand
  622. FROM onek
  623. WHERE onek.thousand < 995
  624. ORDER BY onek.thousand
  625. LIMIT ALL;
  626. -- leave these views