select.sql 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. --
  11. -- Test some cases involving whole-row Var referencing a subquery
  12. --
  13. select foo from (select 1 offset 0) as foo;
  14. select foo from (select null offset 0) as foo;
  15. select foo from (select 'xyzzy',1,null offset 0) as foo;
  16. -- VALUES is also legal as a standalone query or a set-operation member
  17. VALUES (1,2), (3,4+4), (7,77.7);
  18. VALUES (1,2), (3,4+4), (7,77.7)
  19. UNION ALL
  20. SELECT 2+2, 57
  21. UNION ALL
  22. TABLE int8_tbl;
  23. -- corner case: VALUES with no columns
  24. CREATE TEMP TABLE nocols();
  25. --
  26. -- Test ORDER BY options
  27. --
  28. CREATE TEMP TABLE foo (f1 int);
  29. INSERT INTO foo VALUES (42),(3),(10),(7),(null),(null),(1);
  30. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  31. -- check if indexscans do the right things
  32. CREATE INDEX fooi ON foo (f1);
  33. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  34. CREATE INDEX fooi ON foo (f1 DESC);
  35. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  36. CREATE INDEX fooi ON foo (f1 DESC NULLS LAST);
  37. SELECT * FROM foo ORDER BY f1 NULLS FIRST;
  38. select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
  39. select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
  40. select * from onek2 where unique2 = 11 and stringu1 < 'B';
  41. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
  42. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update;
  43. select unique2 from onek2 where unique2 = 11 and stringu1 < 'C';
  44. select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
  45. select unique1, unique2 from onek2
  46. where (unique2 = 11 or unique1 = 0) and stringu1 < 'B';
  47. select unique1, unique2 from onek2
  48. where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
  49. -- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict
  50. -- (see bug #5084)
  51. select * from (values (2),(null),(1)) v(k) where k = k order by k;
  52. select * from (values (2),(null),(1)) v(k) where k = k;