Commit 67ac3808 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Update for new psql formatting.

parent 6e0cc2ac
QUERY: CREATE TABLE CASE_TBL ( --
-- CASE
-- Test the case statement
--
CREATE TABLE CASE_TBL (
i integer, i integer,
f double precision f double precision
); );
QUERY: CREATE TABLE CASE2_TBL ( CREATE TABLE CASE2_TBL (
i integer, i integer,
j integer j integer
); );
QUERY: INSERT INTO CASE_TBL VALUES (1, 10.1); INSERT INTO CASE_TBL VALUES (1, 10.1);
QUERY: INSERT INTO CASE_TBL VALUES (2, 20.2); INSERT INTO CASE_TBL VALUES (2, 20.2);
QUERY: INSERT INTO CASE_TBL VALUES (3, -30.3); INSERT INTO CASE_TBL VALUES (3, -30.3);
QUERY: INSERT INTO CASE_TBL VALUES (4, NULL); INSERT INTO CASE_TBL VALUES (4, NULL);
QUERY: INSERT INTO CASE2_TBL VALUES (1, -1); INSERT INTO CASE2_TBL VALUES (1, -1);
QUERY: INSERT INTO CASE2_TBL VALUES (2, -2); INSERT INTO CASE2_TBL VALUES (2, -2);
QUERY: INSERT INTO CASE2_TBL VALUES (3, -3); INSERT INTO CASE2_TBL VALUES (3, -3);
QUERY: INSERT INTO CASE2_TBL VALUES (2, -4); INSERT INTO CASE2_TBL VALUES (2, -4);
QUERY: INSERT INTO CASE2_TBL VALUES (1, NULL); INSERT INTO CASE2_TBL VALUES (1, NULL);
QUERY: INSERT INTO CASE2_TBL VALUES (NULL, -6); INSERT INTO CASE2_TBL VALUES (NULL, -6);
QUERY: SELECT '3' AS "One", --
-- Simplest examples without tables
--
SELECT '3' AS "One",
CASE CASE
WHEN 1 < 2 THEN 3 WHEN 1 < 2 THEN 3
END AS "Simple WHEN"; END AS "Simple WHEN";
One|Simple WHEN One | Simple WHEN
---+----------- -----+-------------
3| 3 3 | 3
(1 row) (1 row)
QUERY: SELECT '<NULL>' AS "One", SELECT '<NULL>' AS "One",
CASE CASE
WHEN 1 > 2 THEN 3 WHEN 1 > 2 THEN 3
END AS "Simple default"; END AS "Simple default";
One |Simple default One | Simple default
------+-------------- --------+----------------
<NULL>| <NULL> |
(1 row) (1 row)
QUERY: SELECT '3' AS "One", SELECT '3' AS "One",
CASE CASE
WHEN 1 < 2 THEN 3 WHEN 1 < 2 THEN 3
ELSE 4 ELSE 4
END AS "Simple ELSE"; END AS "Simple ELSE";
One|Simple ELSE One | Simple ELSE
---+----------- -----+-------------
3| 3 3 | 3
(1 row) (1 row)
QUERY: SELECT '4' AS "One", SELECT '4' AS "One",
CASE CASE
WHEN 1 > 2 THEN 3 WHEN 1 > 2 THEN 3
ELSE 4 ELSE 4
END AS "ELSE default"; END AS "ELSE default";
One|ELSE default One | ELSE default
---+------------ -----+--------------
4| 4 4 | 4
(1 row) (1 row)
QUERY: SELECT '6' AS "One", SELECT '6' AS "One",
CASE CASE
WHEN 1 > 2 THEN 3 WHEN 1 > 2 THEN 3
WHEN 4 < 5 THEN 6 WHEN 4 < 5 THEN 6
ELSE 7 ELSE 7
END AS "Two WHEN with default"; END AS "Two WHEN with default";
One|Two WHEN with default One | Two WHEN with default
---+--------------------- -----+-----------------------
6| 6 6 | 6
(1 row) (1 row)
QUERY: SELECT '' AS "Five", --
-- Examples of targets involving tables
--
SELECT '' AS "Five",
CASE CASE
WHEN i >= 3 THEN i WHEN i >= 3 THEN i
END AS ">= 3 or Null" END AS ">= 3 or Null"
FROM CASE_TBL; FROM CASE_TBL;
Five|>= 3 or Null Five | >= 3 or Null
----+------------ ------+--------------
| |
| |
| 3 | 3
| 4 | 4
(4 rows) (4 rows)
QUERY: SELECT '' AS "Five", SELECT '' AS "Five",
CASE WHEN i >= 3 THEN (i + i) CASE WHEN i >= 3 THEN (i + i)
ELSE i ELSE i
END AS "Simplest Math" END AS "Simplest Math"
FROM CASE_TBL; FROM CASE_TBL;
Five|Simplest Math Five | Simplest Math
----+------------- ------+---------------
| 1 | 1
| 2 | 2
| 6 | 6
| 8 | 8
(4 rows) (4 rows)
QUERY: SELECT '' AS "Five", i AS "Value", SELECT '' AS "Five", i AS "Value",
CASE WHEN (i < 0) THEN 'small' CASE WHEN (i < 0) THEN 'small'
WHEN (i = 0) THEN 'zero' WHEN (i = 0) THEN 'zero'
WHEN (i = 1) THEN 'one' WHEN (i = 1) THEN 'one'
...@@ -99,15 +109,15 @@ QUERY: SELECT '' AS "Five", i AS "Value", ...@@ -99,15 +109,15 @@ QUERY: SELECT '' AS "Five", i AS "Value",
ELSE 'big' ELSE 'big'
END AS "Category" END AS "Category"
FROM CASE_TBL; FROM CASE_TBL;
Five|Value|Category Five | Value | Category
----+-----+-------- ------+-------+----------
| 1|one | 1 | one
| 2|two | 2 | two
| 3|big | 3 | big
| 4|big | 4 | big
(4 rows) (4 rows)
QUERY: SELECT '' AS "Five", SELECT '' AS "Five",
CASE WHEN ((i < 0) or (i < 0)) THEN 'small' CASE WHEN ((i < 0) or (i < 0)) THEN 'small'
WHEN ((i = 0) or (i = 0)) THEN 'zero' WHEN ((i = 0) or (i = 0)) THEN 'zero'
WHEN ((i = 1) or (i = 1)) THEN 'one' WHEN ((i = 1) or (i = 1)) THEN 'one'
...@@ -115,141 +125,155 @@ QUERY: SELECT '' AS "Five", ...@@ -115,141 +125,155 @@ QUERY: SELECT '' AS "Five",
ELSE 'big' ELSE 'big'
END AS "Category" END AS "Category"
FROM CASE_TBL; FROM CASE_TBL;
Five|Category Five | Category
----+-------- ------+----------
|one | one
|two | two
|big | big
|big | big
(4 rows) (4 rows)
QUERY: SELECT * FROM CASE_TBL WHERE COALESCE(f,i) = 4; --
i|f -- Examples of qualifications involving tables
-+- --
4| --
-- NULLIF() and COALESCE()
-- Shorthand forms for typical CASE constructs
-- defined in the SQL92 standard.
--
SELECT * FROM CASE_TBL WHERE COALESCE(f,i) = 4;
i | f
---+---
4 |
(1 row) (1 row)
QUERY: SELECT * FROM CASE_TBL WHERE NULLIF(f,i) = 2; SELECT * FROM CASE_TBL WHERE NULLIF(f,i) = 2;
i|f i | f
-+- ---+---
(0 rows) (0 rows)
QUERY: SELECT COALESCE(a.f, b.i, b.j) SELECT COALESCE(a.f, b.i, b.j)
FROM CASE_TBL a, CASE2_TBL b; FROM CASE_TBL a, CASE2_TBL b;
case case
----- -------
10.1 10.1
20.2 20.2
-30.3 -30.3
1 1
10.1 10.1
20.2 20.2
-30.3 -30.3
2 2
10.1 10.1
20.2 20.2
-30.3 -30.3
3 3
10.1 10.1
20.2 20.2
-30.3 -30.3
2 2
10.1 10.1
20.2 20.2
-30.3 -30.3
1 1
10.1 10.1
20.2 20.2
-30.3 -30.3
-6 -6
(24 rows) (24 rows)
QUERY: SELECT * SELECT *
FROM CASE_TBL a, CASE2_TBL b FROM CASE_TBL a, CASE2_TBL b
WHERE COALESCE(a.f, b.i, b.j) = 2; WHERE COALESCE(a.f, b.i, b.j) = 2;
i|f|i| j i | f | i | j
-+-+-+-- ---+---+---+----
4| |2|-2 4 | | 2 | -2
4| |2|-4 4 | | 2 | -4
(2 rows) (2 rows)
QUERY: SELECT '' AS Five, NULLIF(a.i,b.i) AS "NULLIF(a.i,b.i)", SELECT '' AS Five, NULLIF(a.i,b.i) AS "NULLIF(a.i,b.i)",
NULLIF(b.i, 4) AS "NULLIF(b.i,4)" NULLIF(b.i, 4) AS "NULLIF(b.i,4)"
FROM CASE_TBL a, CASE2_TBL b; FROM CASE_TBL a, CASE2_TBL b;
five|NULLIF(a.i,b.i)|NULLIF(b.i,4) five | NULLIF(a.i,b.i) | NULLIF(b.i,4)
----+---------------+------------- ------+-----------------+---------------
| | 1 | | 1
| 2| 1 | 2 | 1
| 3| 1 | 3 | 1
| 4| 1 | 4 | 1
| 1| 2 | 1 | 2
| | 2 | | 2
| 3| 2 | 3 | 2
| 4| 2 | 4 | 2
| 1| 3 | 1 | 3
| 2| 3 | 2 | 3
| | 3 | | 3
| 4| 3 | 4 | 3
| 1| 2 | 1 | 2
| | 2 | | 2
| 3| 2 | 3 | 2
| 4| 2 | 4 | 2
| | 1 | | 1
| 2| 1 | 2 | 1
| 3| 1 | 3 | 1
| 4| 1 | 4 | 1
| 1| | 1 |
| 2| | 2 |
| 3| | 3 |
| 4| | 4 |
(24 rows) (24 rows)
QUERY: SELECT '' AS "Two", * SELECT '' AS "Two", *
FROM CASE_TBL a, CASE2_TBL b FROM CASE_TBL a, CASE2_TBL b
WHERE COALESCE(f,b.i) = 2; WHERE COALESCE(f,b.i) = 2;
Two|i|f|i| j Two | i | f | i | j
---+-+-+-+-- -----+---+---+---+----
|4| |2|-2 | 4 | | 2 | -2
|4| |2|-4 | 4 | | 2 | -4
(2 rows) (2 rows)
QUERY: UPDATE CASE_TBL --
-- Examples of updates involving tables
--
UPDATE CASE_TBL
SET i = CASE WHEN i >= 3 THEN (- i) SET i = CASE WHEN i >= 3 THEN (- i)
ELSE (2 * i) END; ELSE (2 * i) END;
QUERY: SELECT * FROM CASE_TBL; SELECT * FROM CASE_TBL;
i| f i | f
--+----- ----+-------
2| 10.1 2 | 10.1
4| 20.2 4 | 20.2
-3|-30.3 -3 | -30.3
-4| -4 |
(4 rows) (4 rows)
QUERY: UPDATE CASE_TBL UPDATE CASE_TBL
SET i = CASE WHEN i >= 2 THEN (2 * i) SET i = CASE WHEN i >= 2 THEN (2 * i)
ELSE (3 * i) END; ELSE (3 * i) END;
QUERY: SELECT * FROM CASE_TBL; SELECT * FROM CASE_TBL;
i| f i | f
---+----- -----+-------
4| 10.1 4 | 10.1
8| 20.2 8 | 20.2
-9|-30.3 -9 | -30.3
-12| -12 |
(4 rows) (4 rows)
QUERY: UPDATE CASE_TBL UPDATE CASE_TBL
SET i = CASE WHEN b.i >= 2 THEN (2 * j) SET i = CASE WHEN b.i >= 2 THEN (2 * j)
ELSE (3 * j) END ELSE (3 * j) END
FROM CASE2_TBL b FROM CASE2_TBL b
WHERE j = -CASE_TBL.i; WHERE j = -CASE_TBL.i;
QUERY: SELECT * FROM CASE_TBL; SELECT * FROM CASE_TBL;
i| f i | f
---+----- -----+-------
8| 20.2 8 | 20.2
-9|-30.3 -9 | -30.3
-12| -12 |
-8| 10.1 -8 | 10.1
(4 rows) (4 rows)
QUERY: DROP TABLE CASE_TBL; --
QUERY: DROP TABLE CASE2_TBL; -- Clean up
--
DROP TABLE CASE_TBL;
DROP TABLE CASE2_TBL;
-- --
-- errors.source -- ERRORS
-- --
-- $Header: /cvsroot/pgsql/src/test/regress/expected/errors.out,v 1.15 2000/01/05 17:31:08 thomas Exp $
-- bad in postquel, but ok in postsql -- bad in postquel, but ok in postsql
select 1 select 1
-- --
......
QUERY: SELECT count(*) FROM onek; --
count -- RANDOM
----- -- Test the random function
1000 --
-- count the number of tuples originally
SELECT count(*) FROM onek;
count
-------
1000
(1 row) (1 row)
QUERY: SELECT count(*) AS random INTO RANDOM_TBL -- select roughly 1/10 of the tuples
-- Assume that the "onek" table has 1000 tuples
-- and try to bracket the correct number so we
-- have a regression test which can pass/fail
-- - thomas 1998-08-17
SELECT count(*) AS random INTO RANDOM_TBL
FROM onek WHERE oidrand(onek.oid, 10); FROM onek WHERE oidrand(onek.oid, 10);
QUERY: INSERT INTO RANDOM_TBL (random) -- select again, the count should be different
INSERT INTO RANDOM_TBL (random)
SELECT count(*) SELECT count(*)
FROM onek WHERE oidrand(onek.oid, 10); FROM onek WHERE oidrand(onek.oid, 10);
QUERY: SELECT random, count(random) FROM RANDOM_TBL -- now test the results for randomness in the correct range
SELECT random, count(random) FROM RANDOM_TBL
GROUP BY random HAVING count(random) > 1; GROUP BY random HAVING count(random) > 1;
random|count random | count
------+----- --------+-------
(0 rows) (0 rows)
QUERY: SELECT random FROM RANDOM_TBL SELECT random FROM RANDOM_TBL
WHERE random NOT BETWEEN 80 AND 120; WHERE random NOT BETWEEN 80 AND 120;
random random
------ --------
(0 rows) (0 rows)
This diff is collapsed.
QUERY: SELECT DISTINCT two FROM tmp; --
two -- SELECT_DISTINCT
--- --
0 --
1 -- awk '{print $3;}' onek.data | sort -n | uniq
--
SELECT DISTINCT two FROM tmp;
two
-----
0
1
(2 rows) (2 rows)
QUERY: SELECT DISTINCT ten FROM tmp; --
ten -- awk '{print $5;}' onek.data | sort -n | uniq
--- --
0 SELECT DISTINCT ten FROM tmp;
1 ten
2 -----
3 0
4 1
5 2
6 3
7 4
8 5
9 6
7
8
9
(10 rows) (10 rows)
QUERY: SELECT DISTINCT string4 FROM tmp; --
string4 -- awk '{print $16;}' onek.data | sort -d | uniq
------- --
AAAAxx SELECT DISTINCT string4 FROM tmp;
HHHHxx string4
OOOOxx ---------
VVVVxx AAAAxx
HHHHxx
OOOOxx
VVVVxx
(4 rows) (4 rows)
QUERY: SELECT DISTINCT two, string4, ten --
-- awk '{print $3,$16,$5;}' onek.data | sort -d | uniq |
-- sort +0n -1 +1d -2 +2n -3
--
SELECT DISTINCT two, string4, ten
FROM tmp FROM tmp
ORDER BY two using <, string4 using <, ten using <; ORDER BY two using <, string4 using <, ten using <;
two|string4|ten two | string4 | ten
---+-------+--- -----+---------+-----
0|AAAAxx | 0 0 | AAAAxx | 0
0|AAAAxx | 2 0 | AAAAxx | 2
0|AAAAxx | 4 0 | AAAAxx | 4
0|AAAAxx | 6 0 | AAAAxx | 6
0|AAAAxx | 8 0 | AAAAxx | 8
0|HHHHxx | 0 0 | HHHHxx | 0
0|HHHHxx | 2 0 | HHHHxx | 2
0|HHHHxx | 4 0 | HHHHxx | 4
0|HHHHxx | 6 0 | HHHHxx | 6
0|HHHHxx | 8 0 | HHHHxx | 8
0|OOOOxx | 0 0 | OOOOxx | 0
0|OOOOxx | 2 0 | OOOOxx | 2
0|OOOOxx | 4 0 | OOOOxx | 4
0|OOOOxx | 6 0 | OOOOxx | 6
0|OOOOxx | 8 0 | OOOOxx | 8
0|VVVVxx | 0 0 | VVVVxx | 0
0|VVVVxx | 2 0 | VVVVxx | 2
0|VVVVxx | 4 0 | VVVVxx | 4
0|VVVVxx | 6 0 | VVVVxx | 6
0|VVVVxx | 8 0 | VVVVxx | 8
1|AAAAxx | 1 1 | AAAAxx | 1
1|AAAAxx | 3 1 | AAAAxx | 3
1|AAAAxx | 5 1 | AAAAxx | 5
1|AAAAxx | 7 1 | AAAAxx | 7
1|AAAAxx | 9 1 | AAAAxx | 9
1|HHHHxx | 1 1 | HHHHxx | 1
1|HHHHxx | 3 1 | HHHHxx | 3
1|HHHHxx | 5 1 | HHHHxx | 5
1|HHHHxx | 7 1 | HHHHxx | 7
1|HHHHxx | 9 1 | HHHHxx | 9
1|OOOOxx | 1 1 | OOOOxx | 1
1|OOOOxx | 3 1 | OOOOxx | 3
1|OOOOxx | 5 1 | OOOOxx | 5
1|OOOOxx | 7 1 | OOOOxx | 7
1|OOOOxx | 9 1 | OOOOxx | 9
1|VVVVxx | 1 1 | VVVVxx | 1
1|VVVVxx | 3 1 | VVVVxx | 3
1|VVVVxx | 5 1 | VVVVxx | 5
1|VVVVxx | 7 1 | VVVVxx | 7
1|VVVVxx | 9 1 | VVVVxx | 9
(40 rows) (40 rows)
QUERY: SELECT DISTINCT p.age FROM person* p ORDER BY age using >; --
age -- awk '{print $2;}' person.data |
--- -- awk '{if(NF!=1){print $2;}else{print;}}' - emp.data |
98 -- awk '{if(NF!=1){print $2;}else{print;}}' - student.data |
88 -- awk 'BEGIN{FS=" ";}{if(NF!=1){print $5;}else{print;}}' - stud_emp.data |
78 -- sort -n -r | uniq
68 --
60 SELECT DISTINCT p.age FROM person* p ORDER BY age using >;
58 age
50 -----
48 98
40 88
38 78
34 68
30 60
28 58
25 50
24 48
23 40
20 38
19 34
18 30
8 28
25
24
23
20
19
18
8
(20 rows) (20 rows)
QUERY: SELECT DISTINCT ON string4 two, string4, ten --
-- SELECT_DISTINCT_ON
--
SELECT DISTINCT ON string4 two, string4, ten
FROM tmp FROM tmp
ORDER BY two using <, string4 using <, ten using <; ORDER BY two using <, string4 using <, ten using <;
two|string4|ten two | string4 | ten
---+-------+--- -----+---------+-----
0|AAAAxx | 0 0 | AAAAxx | 0
0|HHHHxx | 0 0 | HHHHxx | 0
0|OOOOxx | 0 0 | OOOOxx | 0
0|VVVVxx | 0 0 | VVVVxx | 0
1|AAAAxx | 1 1 | AAAAxx | 1
1|HHHHxx | 1 1 | HHHHxx | 1
1|OOOOxx | 1 1 | OOOOxx | 1
1|VVVVxx | 1 1 | VVVVxx | 1
(8 rows) (8 rows)
QUERY: CREATE TABLE test_having (a int, b int, c char(8), d char); --
QUERY: INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A'); -- SELECT_HAVING
QUERY: INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b'); --
QUERY: INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c'); -- load test data
QUERY: INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D'); CREATE TABLE test_having (a int, b int, c char(8), d char);
QUERY: INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e'); INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
QUERY: INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F'); INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b');
QUERY: INSERT INTO test_having VALUES (6, 4, 'cccc', 'g'); INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c');
QUERY: INSERT INTO test_having VALUES (7, 4, 'cccc', 'h'); INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D');
QUERY: INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I'); INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e');
QUERY: INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j'); INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F');
QUERY: SELECT b, c FROM test_having INSERT INTO test_having VALUES (6, 4, 'cccc', 'g');
INSERT INTO test_having VALUES (7, 4, 'cccc', 'h');
INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I');
INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j');
SELECT b, c FROM test_having
GROUP BY b, c HAVING count(*) = 1; GROUP BY b, c HAVING count(*) = 1;
b|c b | c
-+-------- ---+----------
1|XXXX 1 | XXXX
3|bbbb 3 | bbbb
(2 rows) (2 rows)
QUERY: SELECT lower(c), count(c) FROM test_having SELECT lower(c), count(c) FROM test_having
GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a); GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);
lower |count lower | count
--------+----- ----------+-------
bbbb | 3 bbbb | 3
cccc | 4 cccc | 4
xxxx | 1 xxxx | 1
(3 rows) (3 rows)
QUERY: SELECT c, max(a) FROM test_having SELECT c, max(a) FROM test_having
GROUP BY c HAVING count(*) > 2 OR min(a) = max(a); GROUP BY c HAVING count(*) > 2 OR min(a) = max(a);
c |max c | max
--------+--- ----------+-----
XXXX | 0 XXXX | 0
bbbb | 5 bbbb | 5
(2 rows) (2 rows)
QUERY: DROP TABLE test_having; DROP TABLE test_having;
QUERY: SELECT * --
-- SELECT_INTO
--
SELECT *
INTO TABLE tmp1 INTO TABLE tmp1
FROM tmp FROM tmp
WHERE onek.unique1 < 2; WHERE onek.unique1 < 2;
QUERY: DROP TABLE tmp1; DROP TABLE tmp1;
QUERY: SELECT * SELECT *
INTO TABLE tmp1 INTO TABLE tmp1
FROM tmp FROM tmp
WHERE onek2.unique1 < 2; WHERE onek2.unique1 < 2;
QUERY: DROP TABLE tmp1; DROP TABLE tmp1;
QUERY: SELECT 1 AS one WHERE 1 IN (SELECT 1); --
one -- SUBSELECT
--- --
1 SELECT 1 AS one WHERE 1 IN (SELECT 1);
one
-----
1
(1 row) (1 row)
QUERY: SELECT 1 AS zero WHERE 1 NOT IN (SELECT 1); SELECT 1 AS zero WHERE 1 NOT IN (SELECT 1);
zero zero
---- ------
(0 rows) (0 rows)
QUERY: SELECT 1 AS zero WHERE 1 IN (SELECT 2); SELECT 1 AS zero WHERE 1 IN (SELECT 2);
zero zero
---- ------
(0 rows) (0 rows)
QUERY: CREATE TABLE SUBSELECT_TBL ( -- Set up some simple test tables
CREATE TABLE SUBSELECT_TBL (
f1 integer, f1 integer,
f2 integer, f2 integer,
f3 float f3 float
); );
QUERY: INSERT INTO SUBSELECT_TBL VALUES (1, 2, 3); INSERT INTO SUBSELECT_TBL VALUES (1, 2, 3);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (2, 3, 4); INSERT INTO SUBSELECT_TBL VALUES (2, 3, 4);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (3, 4, 5); INSERT INTO SUBSELECT_TBL VALUES (3, 4, 5);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (1, 1, 1); INSERT INTO SUBSELECT_TBL VALUES (1, 1, 1);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (2, 2, 2); INSERT INTO SUBSELECT_TBL VALUES (2, 2, 2);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (3, 3, 3); INSERT INTO SUBSELECT_TBL VALUES (3, 3, 3);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (6, 7, 8); INSERT INTO SUBSELECT_TBL VALUES (6, 7, 8);
QUERY: INSERT INTO SUBSELECT_TBL VALUES (8, 9, NULL); INSERT INTO SUBSELECT_TBL VALUES (8, 9, NULL);
QUERY: SELECT '' AS eight, * FROM SUBSELECT_TBL; SELECT '' AS eight, * FROM SUBSELECT_TBL;
eight|f1|f2|f3 eight | f1 | f2 | f3
-----+--+--+-- -------+----+----+----
| 1| 2| 3 | 1 | 2 | 3
| 2| 3| 4 | 2 | 3 | 4
| 3| 4| 5 | 3 | 4 | 5
| 1| 1| 1 | 1 | 1 | 1
| 2| 2| 2 | 2 | 2 | 2
| 3| 3| 3 | 3 | 3 | 3
| 6| 7| 8 | 6 | 7 | 8
| 8| 9| | 8 | 9 |
(8 rows) (8 rows)
QUERY: SELECT '' AS two, f1 AS "Constant Select" FROM SUBSELECT_TBL -- Uncorrelated subselects
SELECT '' AS two, f1 AS "Constant Select" FROM SUBSELECT_TBL
WHERE f1 IN (SELECT 1); WHERE f1 IN (SELECT 1);
two|Constant Select two | Constant Select
---+--------------- -----+-----------------
| 1 | 1
| 1 | 1
(2 rows) (2 rows)
QUERY: SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL);
six|Uncorrelated Field six | Uncorrelated Field
---+------------------ -----+--------------------
| 1 | 1
| 2 | 2
| 3 | 3
| 1 | 1
| 2 | 2
| 3 | 3
(6 rows) (6 rows)
QUERY: SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE
f2 IN (SELECT f1 FROM SUBSELECT_TBL)); f2 IN (SELECT f1 FROM SUBSELECT_TBL));
six|Uncorrelated Field six | Uncorrelated Field
---+------------------ -----+--------------------
| 1 | 1
| 2 | 2
| 3 | 3
| 1 | 1
| 2 | 2
| 3 | 3
(6 rows) (6 rows)
QUERY: SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" -- Correlated subselects
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = f1); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = f1);
six|Correlated Field|Second Field six | Correlated Field | Second Field
---+----------------+------------ -----+------------------+--------------
| 1| 3 | 1 | 3
| 2| 4 | 2 | 4
| 3| 5 | 3 | 5
| 1| 1 | 1 | 1
| 2| 2 | 2 | 2
| 3| 3 | 3 | 3
(6 rows) (6 rows)
QUERY: SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE CAST(f2 AS float) = f3); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE CAST(f2 AS float) = f3);
six|Correlated Field|Second Field six | Correlated Field | Second Field
---+----------------+------------ -----+------------------+--------------
| 1| 3 | 1 | 3
| 2| 4 | 2 | 4
| 3| 5 | 3 | 5
| 1| 1 | 1 | 1
| 2| 2 | 2 | 2
| 3| 3 | 3 | 3
(6 rows) (6 rows)
QUERY: SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = CAST(f3 AS integer)); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = CAST(f3 AS integer));
ERROR: dtoi4: unable to convert null ERROR: dtoi4: unable to convert null
QUERY: SELECT '' AS five, f1 AS "Correlated Field" SELECT '' AS five, f1 AS "Correlated Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL); WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL);
five|Correlated Field five | Correlated Field
----+---------------- ------+------------------
| 2 | 2
| 3 | 3
| 1 | 1
| 2 | 2
| 3 | 3
(5 rows) (5 rows)
QUERY: SELECT '' AS three, f1 AS "Correlated Field" SELECT '' AS three, f1 AS "Correlated Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL); WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL);
three|Correlated Field three | Correlated Field
-----+---------------- -------+------------------
| 1 | 1
| 6 | 6
| 8 | 8
(3 rows) (3 rows)
QUERY: SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field" --
-- Use some existing tables in the regression test
--
SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
FROM SUBSELECT_TBL ss FROM SUBSELECT_TBL ss
WHERE f1 NOT IN (SELECT f1 FROM INT4_TBL WHERE f1 != ss.f1); WHERE f1 NOT IN (SELECT f1 FROM INT4_TBL WHERE f1 != ss.f1);
eight|Correlated Field|Second Field eight | Correlated Field | Second Field
-----+----------------+------------ -------+------------------+--------------
| 1| 3 | 1 | 3
| 2| 4 | 2 | 4
| 3| 5 | 3 | 5
| 1| 1 | 1 | 1
| 2| 2 | 2 | 2
| 3| 3 | 3 | 3
| 6| 8 | 6 | 8
| 8| | 8 |
(8 rows) (8 rows)
QUERY: SELECT 1 AS two UNION SELECT 2; --
two -- UNION
--- --
1 -- Simple UNION constructs
2 SELECT 1 AS two UNION SELECT 2;
two
-----
1
2
(2 rows) (2 rows)
QUERY: SELECT 1 AS one UNION SELECT 1; SELECT 1 AS one UNION SELECT 1;
one one
--- -----
1 1
(1 row) (1 row)
QUERY: SELECT 1 AS two UNION ALL SELECT 2; SELECT 1 AS two UNION ALL SELECT 2;
two two
--- -----
1 1
2 2
(2 rows) (2 rows)
QUERY: SELECT 1 AS two UNION ALL SELECT 1; SELECT 1 AS two UNION ALL SELECT 1;
two two
--- -----
1 1
1 1
(2 rows) (2 rows)
QUERY: SELECT 1 AS three UNION SELECT 2 UNION SELECT 3; SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
three three
----- -------
1 1
2 2
3 3
(3 rows) (3 rows)
QUERY: SELECT 1 AS two UNION SELECT 2 UNION SELECT 2; SELECT 1 AS two UNION SELECT 2 UNION SELECT 2;
two two
--- -----
1 1
2 2
(2 rows) (2 rows)
QUERY: SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2; SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2;
three three
----- -------
1 1
2 2
2 2
(3 rows) (3 rows)
QUERY: SELECT 1.1 AS two UNION SELECT 2.2; SELECT 1.1 AS two UNION SELECT 2.2;
two two
--- -----
1.1 1.1
2.2 2.2
(2 rows) (2 rows)
QUERY: SELECT 1.1 AS two UNION SELECT 2; -- Mixed types
two SELECT 1.1 AS two UNION SELECT 2;
--- two
1.1 -----
2 1.1
2
(2 rows) (2 rows)
QUERY: SELECT 1 AS two UNION SELECT 2.2; SELECT 1 AS two UNION SELECT 2.2;
two two
--- -----
1 1
2 2
(2 rows) (2 rows)
QUERY: SELECT 1 AS one UNION SELECT 1.1; SELECT 1 AS one UNION SELECT 1.1;
one one
--- -----
1 1
(1 row) (1 row)
QUERY: SELECT 1.1 AS two UNION ALL SELECT 2; SELECT 1.1 AS two UNION ALL SELECT 2;
two two
--- -----
1.1 1.1
2 2
(2 rows) (2 rows)
QUERY: SELECT 1 AS two UNION ALL SELECT 1; SELECT 1 AS two UNION ALL SELECT 1;
two two
--- -----
1 1
1 1
(2 rows) (2 rows)
QUERY: SELECT 1 AS three UNION SELECT 2 UNION SELECT 3; SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
three three
----- -------
1 1
2 2
3 3
(3 rows) (3 rows)
QUERY: SELECT 1 AS two UNION SELECT 2 UNION SELECT 2; SELECT 1 AS two UNION SELECT 2 UNION SELECT 2;
two two
--- -----
1 1
2 2
(2 rows) (2 rows)
QUERY: SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2; SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2;
three three
----- -------
1 1
2 2
2 2
(3 rows) (3 rows)
QUERY: SELECT f1 AS five FROM FLOAT8_TBL --
-- Try testing from tables...
--
SELECT f1 AS five FROM FLOAT8_TBL
UNION UNION
SELECT f1 FROM FLOAT8_TBL; SELECT f1 FROM FLOAT8_TBL;
five five
--------------------- -----------------------
-1.2345678901234e+200 -1.2345678901234e+200
-1004.3 -1004.3
-34.84 -34.84
-1.2345678901234e-200 -1.2345678901234e-200
0 0
(5 rows) (5 rows)
QUERY: SELECT f1 AS ten FROM FLOAT8_TBL SELECT f1 AS ten FROM FLOAT8_TBL
UNION ALL UNION ALL
SELECT f1 FROM FLOAT8_TBL; SELECT f1 FROM FLOAT8_TBL;
ten ten
--------------------- -----------------------
0 0
-34.84 -34.84
-1004.3 -1004.3
-1.2345678901234e+200 -1.2345678901234e+200
-1.2345678901234e-200 -1.2345678901234e-200
0 0
-34.84 -34.84
-1004.3 -1004.3
-1.2345678901234e+200 -1.2345678901234e+200
-1.2345678901234e-200 -1.2345678901234e-200
(10 rows) (10 rows)
QUERY: SELECT f1 AS nine FROM FLOAT8_TBL SELECT f1 AS nine FROM FLOAT8_TBL
UNION UNION
SELECT f1 FROM INT4_TBL; SELECT f1 FROM INT4_TBL;
nine nine
--------------------- -----------------------
-1.2345678901234e+200 -1.2345678901234e+200
-2147483647 -2147483647
-123456 -123456
-1004.3 -1004.3
-34.84 -34.84
-1.2345678901234e-200 -1.2345678901234e-200
0 0
123456 123456
2147483647 2147483647
(9 rows) (9 rows)
QUERY: SELECT f1 AS ten FROM FLOAT8_TBL SELECT f1 AS ten FROM FLOAT8_TBL
UNION ALL UNION ALL
SELECT f1 FROM INT4_TBL; SELECT f1 FROM INT4_TBL;
ten ten
--------------------- -----------------------
0 0
-34.84 -34.84
-1004.3 -1004.3
-1.2345678901234e+200 -1.2345678901234e+200
-1.2345678901234e-200 -1.2345678901234e-200
0 0
123456 123456
-123456 -123456
2147483647 2147483647
-2147483647 -2147483647
(10 rows) (10 rows)
QUERY: SELECT f1 AS five FROM FLOAT8_TBL SELECT f1 AS five FROM FLOAT8_TBL
WHERE f1 BETWEEN -1e6 AND 1e6 WHERE f1 BETWEEN -1e6 AND 1e6
UNION UNION
SELECT f1 FROM INT4_TBL SELECT f1 FROM INT4_TBL
WHERE f1 BETWEEN 0 AND 1000000; WHERE f1 BETWEEN 0 AND 1000000;
five five
--------------------- -----------------------
-1004.3 -1004.3
-34.84 -34.84
-1.2345678901234e-200 -1.2345678901234e-200
0 0
123456 123456
(5 rows) (5 rows)
QUERY: SELECT f1 AS five FROM VARCHAR_TBL SELECT f1 AS five FROM VARCHAR_TBL
UNION UNION
SELECT f1 FROM CHAR_TBL; SELECT f1 FROM CHAR_TBL;
five five
---- ------
a a
a a
ab ab
ab ab
abcd abcd
(5 rows) (5 rows)
QUERY: SELECT f1 AS three FROM VARCHAR_TBL SELECT f1 AS three FROM VARCHAR_TBL
UNION UNION
SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL; SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL;
three three
----- -------
a a
ab ab
abcd abcd
(3 rows) (3 rows)
QUERY: SELECT f1 AS eight FROM VARCHAR_TBL SELECT f1 AS eight FROM VARCHAR_TBL
UNION ALL UNION ALL
SELECT f1 FROM CHAR_TBL; SELECT f1 FROM CHAR_TBL;
eight eight
----- -------
a a
ab ab
abcd abcd
abcd abcd
a a
ab ab
abcd abcd
abcd abcd
(8 rows) (8 rows)
QUERY: SELECT f1 AS five FROM TEXT_TBL SELECT f1 AS five FROM TEXT_TBL
UNION UNION
SELECT f1 FROM VARCHAR_TBL SELECT f1 FROM VARCHAR_TBL
UNION UNION
SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL; SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL;
five five
----------------- -------------------
a a
ab ab
abcd abcd
doh! doh!
hi de ho neighbor hi de ho neighbor
(5 rows) (5 rows)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment