123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- --
- -- SELECT
- --
- -- btree index
- -- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1
- --
- SELECT * FROM onek
- WHERE onek.unique1 < 10
- ORDER BY onek.unique1;
- unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
- 0 | 998 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | AAAAAA | KMBAAA | OOOOxx
- 1 | 214 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | BAAAAA | GIAAAA | OOOOxx
- 2 | 326 | 0 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 4 | 5 | CAAAAA | OMAAAA | OOOOxx
- 3 | 431 | 1 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 6 | 7 | DAAAAA | PQAAAA | VVVVxx
- 4 | 833 | 0 | 0 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 8 | 9 | EAAAAA | BGBAAA | HHHHxx
- 5 | 541 | 1 | 1 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 10 | 11 | FAAAAA | VUAAAA | HHHHxx
- 6 | 978 | 0 | 2 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 12 | 13 | GAAAAA | QLBAAA | OOOOxx
- 7 | 647 | 1 | 3 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 14 | 15 | HAAAAA | XYAAAA | VVVVxx
- 8 | 653 | 0 | 0 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 16 | 17 | IAAAAA | DZAAAA | HHHHxx
- 9 | 49 | 1 | 1 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 18 | 19 | JAAAAA | XBAAAA | HHHHxx
- (10 rows)
- --
- -- Test some cases involving whole-row Var referencing a subquery
- --
- select foo from (select 1 offset 0) as foo;
- foo
- -----
- (1)
- (1 row)
- select foo from (select null offset 0) as foo;
- foo
- -----
- ()
- (1 row)
- select foo from (select 'xyzzy',1,null offset 0) as foo;
- foo
- ------------
- (xyzzy,1,)
- (1 row)
- -- VALUES is also legal as a standalone query or a set-operation member
- VALUES (1,2), (3,4+4), (7,77.7);
- column1 | column2
- ---------+---------
- 1 | 2
- 3 | 8
- 7 | 77.7
- (3 rows)
- VALUES (1,2), (3,4+4), (7,77.7)
- UNION ALL
- SELECT 2+2, 57
- UNION ALL
- TABLE int8_tbl;
- column1 | column2
- ------------------+-------------------
- 1 | 2
- 3 | 8
- 7 | 77.7
- 4 | 57
- 123 | 456
- 123 | 4567890123456789
- 4567890123456789 | 123
- 4567890123456789 | 4567890123456789
- 4567890123456789 | -4567890123456789
- (9 rows)
- -- corner case: VALUES with no columns
- CREATE TEMP TABLE nocols();
- --
- -- Test ORDER BY options
- --
- CREATE TEMP TABLE foo (f1 int);
- INSERT INTO foo VALUES (42),(3),(10),(7),(null),(null),(1);
- SELECT * FROM foo ORDER BY f1 NULLS FIRST;
- f1
- ----
-
-
- 1
- 3
- 7
- 10
- 42
- (7 rows)
- -- check if indexscans do the right things
- CREATE INDEX fooi ON foo (f1);
- SELECT * FROM foo ORDER BY f1 NULLS FIRST;
- f1
- ----
-
-
- 1
- 3
- 7
- 10
- 42
- (7 rows)
- CREATE INDEX fooi ON foo (f1 DESC);
- SELECT * FROM foo ORDER BY f1 NULLS FIRST;
- f1
- ----
-
-
- 1
- 3
- 7
- 10
- 42
- (7 rows)
- CREATE INDEX fooi ON foo (f1 DESC NULLS LAST);
- SELECT * FROM foo ORDER BY f1 NULLS FIRST;
- f1
- ----
-
-
- 1
- 3
- 7
- 10
- 42
- (7 rows)
- select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
- unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
- 494 | 11 | 0 | 2 | 4 | 14 | 4 | 94 | 94 | 494 | 494 | 8 | 9 | ATAAAA | LAAAAA | VVVVxx
- (1 row)
- select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA';
- unique2
- ---------
- 11
- (1 row)
- select * from onek2 where unique2 = 11 and stringu1 < 'B';
- unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
- 494 | 11 | 0 | 2 | 4 | 14 | 4 | 94 | 94 | 494 | 494 | 8 | 9 | ATAAAA | LAAAAA | VVVVxx
- (1 row)
- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
- unique2
- ---------
- 11
- (1 row)
- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update;
- unique2
- ---------
- 11
- (1 row)
- select unique2 from onek2 where unique2 = 11 and stringu1 < 'C';
- unique2
- ---------
- 11
- (1 row)
- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B';
- unique2
- ---------
- 11
- (1 row)
- select unique1, unique2 from onek2
- where (unique2 = 11 or unique1 = 0) and stringu1 < 'B';
- unique1 | unique2
- ---------+---------
- 494 | 11
- 0 | 998
- (2 rows)
- select unique1, unique2 from onek2
- where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
- unique1 | unique2
- ---------+---------
- 494 | 11
- 0 | 998
- (2 rows)
- -- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict
- -- (see bug #5084)
- select * from (values (2),(null),(1)) v(k) where k = k order by k;
- k
- ---
- 1
- 2
- (2 rows)
- select * from (values (2),(null),(1)) v(k) where k = k;
- k
- ---
- 2
- 1
- (2 rows)
|