select.out 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. --
  2. -- SELECT
  3. --
  4. -- btree index
  5. -- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1
  6. --
  7. SELECT * FROM onek
  8. WHERE onek.unique1 < 10
  9. ORDER BY onek.unique1;
  10. unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
  11. ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
  12. 0 | 998 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | AAAAAA | KMBAAA | OOOOxx
  13. 1 | 214 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | BAAAAA | GIAAAA | OOOOxx
  14. 2 | 326 | 0 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 4 | 5 | CAAAAA | OMAAAA | OOOOxx
  15. 3 | 431 | 1 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 6 | 7 | DAAAAA | PQAAAA | VVVVxx
  16. 4 | 833 | 0 | 0 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 8 | 9 | EAAAAA | BGBAAA | HHHHxx
  17. 5 | 541 | 1 | 1 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 10 | 11 | FAAAAA | VUAAAA | HHHHxx
  18. 6 | 978 | 0 | 2 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 12 | 13 | GAAAAA | QLBAAA | OOOOxx
  19. 7 | 647 | 1 | 3 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 14 | 15 | HAAAAA | XYAAAA | VVVVxx
  20. 8 | 653 | 0 | 0 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 16 | 17 | IAAAAA | DZAAAA | HHHHxx
  21. 9 | 49 | 1 | 1 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 18 | 19 | JAAAAA | XBAAAA | HHHHxx
  22. (10 rows)
  23. --
  24. -- Test some cases involving whole-row Var referencing a subquery
  25. --
  26. select foo from (select 1 offset 0) as foo;
  27. foo
  28. -----
  29. (1)
  30. (1 row)
  31. select foo from (select null offset 0) as foo;
  32. foo
  33. -----
  34. ()
  35. (1 row)
  36. select foo from (select 'xyzzy',1,null offset 0) as foo;
  37. foo
  38. ------------
  39. (xyzzy,1,)
  40. (1 row)
  41. -- VALUES is also legal as a standalone query or a set-operation member
  42. VALUES (1,2), (3,4+4), (7,77.7);
  43. column1 | column2
  44. ---------+---------
  45. 1 | 2
  46. 3 | 8
  47. 7 | 77.7
  48. (3 rows)
  49. VALUES (1,2), (3,4+4), (7,77.7)
  50. UNION ALL
  51. SELECT 2+2, 57
  52. UNION ALL
  53. TABLE int8_tbl;
  54. column1 | column2
  55. ------------------+-------------------
  56. 1 | 2
  57. 3 | 8
  58. 7 | 77.7
  59. 4 | 57
  60. 123 | 456
  61. 123 | 4567890123456789
  62. 4567890123456789 | 123
  63. 4567890123456789 | 4567890123456789
  64. 4567890123456789 | -4567890123456789
  65. (9 rows)
  66. -- corner case: VALUES with no columns
  67. CREATE TEMP TABLE nocols();
  68. --
  69. -- Test ORDER BY options
  70. --
  71. CREATE TEMP TABLE foo (f1 int);
  72. INSERT INTO foo VALUES (42),(3),(10),(7),(null),(null),(1);
  73. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  74. f1
  75. ----
  76. 1
  77. 3
  78. 7
  79. 10
  80. 42
  81. (7 rows)
  82. -- check if indexscans do the right things
  83. CREATE INDEX fooi ON foo (f1);
  84. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  85. f1
  86. ----
  87. 1
  88. 3
  89. 7
  90. 10
  91. 42
  92. (7 rows)
  93. CREATE INDEX fooi ON foo (f1 DESC);
  94. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  95. f1
  96. ----
  97. 1
  98. 3
  99. 7
  100. 10
  101. 42
  102. (7 rows)
  103. CREATE INDEX fooi ON foo (f1 DESC NULLS LAST);
  104. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  105. f1
  106. ----
  107. 1
  108. 3
  109. 7
  110. 10
  111. 42
  112. (7 rows)
  113. select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
  114. unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
  115. ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
  116. 494 | 11 | 0 | 2 | 4 | 14 | 4 | 94 | 94 | 494 | 494 | 8 | 9 | ATAAAA | LAAAAA | VVVVxx
  117. (1 row)
  118. select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
  119. unique2
  120. ---------
  121. 11
  122. (1 row)
  123. select * from onek2 where unique2 = 11 and stringu1 < 'B';
  124. unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
  125. ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
  126. 494 | 11 | 0 | 2 | 4 | 14 | 4 | 94 | 94 | 494 | 494 | 8 | 9 | ATAAAA | LAAAAA | VVVVxx
  127. (1 row)
  128. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
  129. unique2
  130. ---------
  131. 11
  132. (1 row)
  133. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update;
  134. unique2
  135. ---------
  136. 11
  137. (1 row)
  138. select unique2 from onek2 where unique2 = 11 and stringu1 < 'C';
  139. unique2
  140. ---------
  141. 11
  142. (1 row)
  143. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
  144. unique2
  145. ---------
  146. 11
  147. (1 row)
  148. select unique1, unique2 from onek2
  149. where (unique2 = 11 or unique1 = 0) and stringu1 < 'B';
  150. unique1 | unique2
  151. ---------+---------
  152. 494 | 11
  153. 0 | 998
  154. (2 rows)
  155. select unique1, unique2 from onek2
  156. where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
  157. unique1 | unique2
  158. ---------+---------
  159. 494 | 11
  160. 0 | 998
  161. (2 rows)
  162. -- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict
  163. -- (see bug #5084)
  164. select * from (values (2),(null),(1)) v(k) where k = k order by k;
  165. k
  166. ---
  167. 1
  168. 2
  169. (2 rows)
  170. select * from (values (2),(null),(1)) v(k) where k = k;
  171. k
  172. ---
  173. 2
  174. 1
  175. (2 rows)