mirror of https://github.com/postgres/postgres
Update for new psql formatting.
This commit is contained in:
parent
6e0cc2ac45
commit
67ac38085c
|
@ -1,97 +1,107 @@
|
||||||
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",
|
||||||
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",
|
||||||
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;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
--
|
--
|
||||||
-- 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
|
||||||
--
|
--
|
||||||
|
|
|
@ -1,23 +1,35 @@
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,303 +1,367 @@
|
||||||
QUERY: SELECT onek.* WHERE onek.unique1 < 10;
|
--
|
||||||
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4
|
-- SELECT
|
||||||
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+-------
|
--
|
||||||
0| 998| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1|AAAAAA |KMBAAA |OOOOxx
|
-- btree index
|
||||||
1| 214| 1| 1| 1| 1| 1| 1| 1| 1| 1| 2| 3|BAAAAA |GIAAAA |OOOOxx
|
-- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1
|
||||||
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
|
SELECT onek.* WHERE onek.unique1 < 10;
|
||||||
4| 833| 0| 0| 4| 4| 4| 4| 4| 4| 4| 8| 9|EAAAAA |BGBAAA |HHHHxx
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
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
|
0 | 998 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | AAAAAA | KMBAAA | OOOOxx
|
||||||
7| 647| 1| 3| 7| 7| 7| 7| 7| 7| 7| 14| 15|HAAAAA |XYAAAA |VVVVxx
|
1 | 214 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | BAAAAA | GIAAAA | OOOOxx
|
||||||
8| 653| 0| 0| 8| 8| 8| 8| 8| 8| 8| 16| 17|IAAAAA |DZAAAA |HHHHxx
|
2 | 326 | 0 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 4 | 5 | CAAAAA | OMAAAA | OOOOxx
|
||||||
9| 49| 1| 1| 9| 9| 9| 9| 9| 9| 9| 18| 19|JAAAAA |XBAAAA |HHHHxx
|
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)
|
(10 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.stringu1
|
--
|
||||||
WHERE onek.unique1 < 20
|
-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.stringu1
|
||||||
|
WHERE onek.unique1 < 20
|
||||||
ORDER BY unique1 using >;
|
ORDER BY unique1 using >;
|
||||||
unique1|stringu1
|
unique1 | stringu1
|
||||||
-------+--------
|
---------+----------
|
||||||
19|TAAAAA
|
19 | TAAAAA
|
||||||
18|SAAAAA
|
18 | SAAAAA
|
||||||
17|RAAAAA
|
17 | RAAAAA
|
||||||
16|QAAAAA
|
16 | QAAAAA
|
||||||
15|PAAAAA
|
15 | PAAAAA
|
||||||
14|OAAAAA
|
14 | OAAAAA
|
||||||
13|NAAAAA
|
13 | NAAAAA
|
||||||
12|MAAAAA
|
12 | MAAAAA
|
||||||
11|LAAAAA
|
11 | LAAAAA
|
||||||
10|KAAAAA
|
10 | KAAAAA
|
||||||
9|JAAAAA
|
9 | JAAAAA
|
||||||
8|IAAAAA
|
8 | IAAAAA
|
||||||
7|HAAAAA
|
7 | HAAAAA
|
||||||
6|GAAAAA
|
6 | GAAAAA
|
||||||
5|FAAAAA
|
5 | FAAAAA
|
||||||
4|EAAAAA
|
4 | EAAAAA
|
||||||
3|DAAAAA
|
3 | DAAAAA
|
||||||
2|CAAAAA
|
2 | CAAAAA
|
||||||
1|BAAAAA
|
1 | BAAAAA
|
||||||
0|AAAAAA
|
0 | AAAAAA
|
||||||
(20 rows)
|
(20 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.stringu1
|
--
|
||||||
WHERE onek.unique1 > 980
|
-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.stringu1
|
||||||
|
WHERE onek.unique1 > 980
|
||||||
ORDER BY stringu1 using <;
|
ORDER BY stringu1 using <;
|
||||||
unique1|stringu1
|
unique1 | stringu1
|
||||||
-------+--------
|
---------+----------
|
||||||
988|AMAAAA
|
988 | AMAAAA
|
||||||
989|BMAAAA
|
989 | BMAAAA
|
||||||
990|CMAAAA
|
990 | CMAAAA
|
||||||
991|DMAAAA
|
991 | DMAAAA
|
||||||
992|EMAAAA
|
992 | EMAAAA
|
||||||
993|FMAAAA
|
993 | FMAAAA
|
||||||
994|GMAAAA
|
994 | GMAAAA
|
||||||
995|HMAAAA
|
995 | HMAAAA
|
||||||
996|IMAAAA
|
996 | IMAAAA
|
||||||
997|JMAAAA
|
997 | JMAAAA
|
||||||
998|KMAAAA
|
998 | KMAAAA
|
||||||
999|LMAAAA
|
999 | LMAAAA
|
||||||
981|TLAAAA
|
981 | TLAAAA
|
||||||
982|ULAAAA
|
982 | ULAAAA
|
||||||
983|VLAAAA
|
983 | VLAAAA
|
||||||
984|WLAAAA
|
984 | WLAAAA
|
||||||
985|XLAAAA
|
985 | XLAAAA
|
||||||
986|YLAAAA
|
986 | YLAAAA
|
||||||
987|ZLAAAA
|
987 | ZLAAAA
|
||||||
(19 rows)
|
(19 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.string4
|
|
||||||
WHERE onek.unique1 > 980
|
--
|
||||||
|
-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data |
|
||||||
|
-- sort +1d -2 +0nr -1
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.string4
|
||||||
|
WHERE onek.unique1 > 980
|
||||||
ORDER BY string4 using <, unique1 using >;
|
ORDER BY string4 using <, unique1 using >;
|
||||||
unique1|string4
|
unique1 | string4
|
||||||
-------+-------
|
---------+---------
|
||||||
999|AAAAxx
|
999 | AAAAxx
|
||||||
995|AAAAxx
|
995 | AAAAxx
|
||||||
983|AAAAxx
|
983 | AAAAxx
|
||||||
982|AAAAxx
|
982 | AAAAxx
|
||||||
981|AAAAxx
|
981 | AAAAxx
|
||||||
998|HHHHxx
|
998 | HHHHxx
|
||||||
997|HHHHxx
|
997 | HHHHxx
|
||||||
993|HHHHxx
|
993 | HHHHxx
|
||||||
990|HHHHxx
|
990 | HHHHxx
|
||||||
986|HHHHxx
|
986 | HHHHxx
|
||||||
996|OOOOxx
|
996 | OOOOxx
|
||||||
991|OOOOxx
|
991 | OOOOxx
|
||||||
988|OOOOxx
|
988 | OOOOxx
|
||||||
987|OOOOxx
|
987 | OOOOxx
|
||||||
985|OOOOxx
|
985 | OOOOxx
|
||||||
994|VVVVxx
|
994 | VVVVxx
|
||||||
992|VVVVxx
|
992 | VVVVxx
|
||||||
989|VVVVxx
|
989 | VVVVxx
|
||||||
984|VVVVxx
|
984 | VVVVxx
|
||||||
(19 rows)
|
(19 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.string4
|
|
||||||
|
--
|
||||||
|
-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data |
|
||||||
|
-- sort +1dr -2 +0n -1
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.string4
|
||||||
WHERE onek.unique1 > 980
|
WHERE onek.unique1 > 980
|
||||||
ORDER BY string4 using >, unique1 using <;
|
ORDER BY string4 using >, unique1 using <;
|
||||||
unique1|string4
|
unique1 | string4
|
||||||
-------+-------
|
---------+---------
|
||||||
984|VVVVxx
|
984 | VVVVxx
|
||||||
989|VVVVxx
|
989 | VVVVxx
|
||||||
992|VVVVxx
|
992 | VVVVxx
|
||||||
994|VVVVxx
|
994 | VVVVxx
|
||||||
985|OOOOxx
|
985 | OOOOxx
|
||||||
987|OOOOxx
|
987 | OOOOxx
|
||||||
988|OOOOxx
|
988 | OOOOxx
|
||||||
991|OOOOxx
|
991 | OOOOxx
|
||||||
996|OOOOxx
|
996 | OOOOxx
|
||||||
986|HHHHxx
|
986 | HHHHxx
|
||||||
990|HHHHxx
|
990 | HHHHxx
|
||||||
993|HHHHxx
|
993 | HHHHxx
|
||||||
997|HHHHxx
|
997 | HHHHxx
|
||||||
998|HHHHxx
|
998 | HHHHxx
|
||||||
981|AAAAxx
|
981 | AAAAxx
|
||||||
982|AAAAxx
|
982 | AAAAxx
|
||||||
983|AAAAxx
|
983 | AAAAxx
|
||||||
995|AAAAxx
|
995 | AAAAxx
|
||||||
999|AAAAxx
|
999 | AAAAxx
|
||||||
(19 rows)
|
(19 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.string4
|
|
||||||
|
--
|
||||||
|
-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data |
|
||||||
|
-- sort +0nr -1 +1d -2
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.string4
|
||||||
WHERE onek.unique1 < 20
|
WHERE onek.unique1 < 20
|
||||||
ORDER BY unique1 using >, string4 using <;
|
ORDER BY unique1 using >, string4 using <;
|
||||||
unique1|string4
|
unique1 | string4
|
||||||
-------+-------
|
---------+---------
|
||||||
19|OOOOxx
|
19 | OOOOxx
|
||||||
18|VVVVxx
|
18 | VVVVxx
|
||||||
17|HHHHxx
|
17 | HHHHxx
|
||||||
16|OOOOxx
|
16 | OOOOxx
|
||||||
15|VVVVxx
|
15 | VVVVxx
|
||||||
14|AAAAxx
|
14 | AAAAxx
|
||||||
13|OOOOxx
|
13 | OOOOxx
|
||||||
12|AAAAxx
|
12 | AAAAxx
|
||||||
11|OOOOxx
|
11 | OOOOxx
|
||||||
10|AAAAxx
|
10 | AAAAxx
|
||||||
9|HHHHxx
|
9 | HHHHxx
|
||||||
8|HHHHxx
|
8 | HHHHxx
|
||||||
7|VVVVxx
|
7 | VVVVxx
|
||||||
6|OOOOxx
|
6 | OOOOxx
|
||||||
5|HHHHxx
|
5 | HHHHxx
|
||||||
4|HHHHxx
|
4 | HHHHxx
|
||||||
3|VVVVxx
|
3 | VVVVxx
|
||||||
2|OOOOxx
|
2 | OOOOxx
|
||||||
1|OOOOxx
|
1 | OOOOxx
|
||||||
0|OOOOxx
|
0 | OOOOxx
|
||||||
(20 rows)
|
(20 rows)
|
||||||
|
|
||||||
QUERY: SELECT onek.unique1, onek.string4
|
--
|
||||||
WHERE onek.unique1 < 20
|
-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data |
|
||||||
|
-- sort +0n -1 +1dr -2
|
||||||
|
--
|
||||||
|
SELECT onek.unique1, onek.string4
|
||||||
|
WHERE onek.unique1 < 20
|
||||||
ORDER BY unique1 using <, string4 using >;
|
ORDER BY unique1 using <, string4 using >;
|
||||||
unique1|string4
|
unique1 | string4
|
||||||
-------+-------
|
---------+---------
|
||||||
0|OOOOxx
|
0 | OOOOxx
|
||||||
1|OOOOxx
|
1 | OOOOxx
|
||||||
2|OOOOxx
|
2 | OOOOxx
|
||||||
3|VVVVxx
|
3 | VVVVxx
|
||||||
4|HHHHxx
|
4 | HHHHxx
|
||||||
5|HHHHxx
|
5 | HHHHxx
|
||||||
6|OOOOxx
|
6 | OOOOxx
|
||||||
7|VVVVxx
|
7 | VVVVxx
|
||||||
8|HHHHxx
|
8 | HHHHxx
|
||||||
9|HHHHxx
|
9 | HHHHxx
|
||||||
10|AAAAxx
|
10 | AAAAxx
|
||||||
11|OOOOxx
|
11 | OOOOxx
|
||||||
12|AAAAxx
|
12 | AAAAxx
|
||||||
13|OOOOxx
|
13 | OOOOxx
|
||||||
14|AAAAxx
|
14 | AAAAxx
|
||||||
15|VVVVxx
|
15 | VVVVxx
|
||||||
16|OOOOxx
|
16 | OOOOxx
|
||||||
17|HHHHxx
|
17 | HHHHxx
|
||||||
18|VVVVxx
|
18 | VVVVxx
|
||||||
19|OOOOxx
|
19 | OOOOxx
|
||||||
(20 rows)
|
(20 rows)
|
||||||
|
|
||||||
QUERY: SELECT two, stringu1, ten, string4
|
--
|
||||||
|
-- partial btree index
|
||||||
|
-- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1
|
||||||
|
--
|
||||||
|
--SELECT onek2.* WHERE onek2.unique1 < 10;
|
||||||
|
--
|
||||||
|
-- partial btree index
|
||||||
|
-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1
|
||||||
|
--
|
||||||
|
--SELECT onek2.unique1, onek2.stringu1
|
||||||
|
-- WHERE onek2.unique1 < 20
|
||||||
|
-- ORDER BY unique1 using >;
|
||||||
|
--
|
||||||
|
-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2
|
||||||
|
--
|
||||||
|
--SELECT onek2.unique1, onek2.stringu1
|
||||||
|
-- WHERE onek2.unique1 > 980
|
||||||
|
-- ORDER BY stringu1 using <;
|
||||||
|
|
||||||
|
SELECT two, stringu1, ten, string4
|
||||||
INTO TABLE tmp
|
INTO TABLE tmp
|
||||||
FROM onek;
|
FROM onek;
|
||||||
QUERY: SELECT p.name, p.age FROM person* p;
|
--
|
||||||
name |age
|
-- awk '{print $1,$2;}' person.data |
|
||||||
-------+---
|
-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data |
|
||||||
mike | 40
|
-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data |
|
||||||
joe | 20
|
-- awk 'BEGIN{FS=" ";}{if(NF!=2){print $4,$5;}else{print;}}' - stud_emp.data
|
||||||
sally | 34
|
--
|
||||||
sandra | 19
|
-- SELECT name, age FROM person*; ??? check if different
|
||||||
alex | 30
|
SELECT p.name, p.age FROM person* p;
|
||||||
sue | 50
|
name | age
|
||||||
denise | 24
|
---------+-----
|
||||||
sarah | 88
|
mike | 40
|
||||||
teresa | 38
|
joe | 20
|
||||||
nan | 28
|
sally | 34
|
||||||
leah | 68
|
sandra | 19
|
||||||
wendy | 78
|
alex | 30
|
||||||
melissa| 28
|
sue | 50
|
||||||
joan | 18
|
denise | 24
|
||||||
mary | 8
|
sarah | 88
|
||||||
jane | 58
|
teresa | 38
|
||||||
liza | 38
|
nan | 28
|
||||||
jean | 28
|
leah | 68
|
||||||
jenifer| 38
|
wendy | 78
|
||||||
juanita| 58
|
melissa | 28
|
||||||
susan | 78
|
joan | 18
|
||||||
zena | 98
|
mary | 8
|
||||||
martie | 88
|
jane | 58
|
||||||
chris | 78
|
liza | 38
|
||||||
pat | 18
|
jean | 28
|
||||||
zola | 58
|
jenifer | 38
|
||||||
louise | 98
|
juanita | 58
|
||||||
edna | 18
|
susan | 78
|
||||||
bertha | 88
|
zena | 98
|
||||||
sumi | 38
|
martie | 88
|
||||||
koko | 88
|
chris | 78
|
||||||
gina | 18
|
pat | 18
|
||||||
rean | 48
|
zola | 58
|
||||||
sharon | 78
|
louise | 98
|
||||||
paula | 68
|
edna | 18
|
||||||
julie | 68
|
bertha | 88
|
||||||
belinda| 38
|
sumi | 38
|
||||||
karen | 48
|
koko | 88
|
||||||
carina | 58
|
gina | 18
|
||||||
diane | 18
|
rean | 48
|
||||||
esther | 98
|
sharon | 78
|
||||||
trudy | 88
|
paula | 68
|
||||||
fanny | 8
|
julie | 68
|
||||||
carmen | 78
|
belinda | 38
|
||||||
lita | 25
|
karen | 48
|
||||||
pamela | 48
|
carina | 58
|
||||||
sandy | 38
|
diane | 18
|
||||||
trisha | 88
|
esther | 98
|
||||||
vera | 78
|
trudy | 88
|
||||||
velma | 68
|
fanny | 8
|
||||||
sharon | 25
|
carmen | 78
|
||||||
sam | 30
|
lita | 25
|
||||||
bill | 20
|
pamela | 48
|
||||||
fred | 28
|
sandy | 38
|
||||||
larry | 60
|
trisha | 88
|
||||||
jeff | 23
|
vera | 78
|
||||||
cim | 30
|
velma | 68
|
||||||
linda | 19
|
sharon | 25
|
||||||
|
sam | 30
|
||||||
|
bill | 20
|
||||||
|
fred | 28
|
||||||
|
larry | 60
|
||||||
|
jeff | 23
|
||||||
|
cim | 30
|
||||||
|
linda | 19
|
||||||
(58 rows)
|
(58 rows)
|
||||||
|
|
||||||
QUERY: SELECT p.name, p.age FROM person* p ORDER BY age using >, name;
|
--
|
||||||
name |age
|
-- awk '{print $1,$2;}' person.data |
|
||||||
-------+---
|
-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data |
|
||||||
esther | 98
|
-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data |
|
||||||
louise | 98
|
-- awk 'BEGIN{FS=" ";}{if(NF!=1){print $4,$5;}else{print;}}' - stud_emp.data |
|
||||||
zena | 98
|
-- sort +1nr -2
|
||||||
bertha | 88
|
--
|
||||||
koko | 88
|
SELECT p.name, p.age FROM person* p ORDER BY age using >, name;
|
||||||
martie | 88
|
name | age
|
||||||
sarah | 88
|
---------+-----
|
||||||
trisha | 88
|
esther | 98
|
||||||
trudy | 88
|
louise | 98
|
||||||
carmen | 78
|
zena | 98
|
||||||
chris | 78
|
bertha | 88
|
||||||
sharon | 78
|
koko | 88
|
||||||
susan | 78
|
martie | 88
|
||||||
vera | 78
|
sarah | 88
|
||||||
wendy | 78
|
trisha | 88
|
||||||
julie | 68
|
trudy | 88
|
||||||
leah | 68
|
carmen | 78
|
||||||
paula | 68
|
chris | 78
|
||||||
velma | 68
|
sharon | 78
|
||||||
larry | 60
|
susan | 78
|
||||||
carina | 58
|
vera | 78
|
||||||
jane | 58
|
wendy | 78
|
||||||
juanita| 58
|
julie | 68
|
||||||
zola | 58
|
leah | 68
|
||||||
sue | 50
|
paula | 68
|
||||||
karen | 48
|
velma | 68
|
||||||
pamela | 48
|
larry | 60
|
||||||
rean | 48
|
carina | 58
|
||||||
mike | 40
|
jane | 58
|
||||||
belinda| 38
|
juanita | 58
|
||||||
jenifer| 38
|
zola | 58
|
||||||
liza | 38
|
sue | 50
|
||||||
sandy | 38
|
karen | 48
|
||||||
sumi | 38
|
pamela | 48
|
||||||
teresa | 38
|
rean | 48
|
||||||
sally | 34
|
mike | 40
|
||||||
alex | 30
|
belinda | 38
|
||||||
cim | 30
|
jenifer | 38
|
||||||
sam | 30
|
liza | 38
|
||||||
fred | 28
|
sandy | 38
|
||||||
jean | 28
|
sumi | 38
|
||||||
melissa| 28
|
teresa | 38
|
||||||
nan | 28
|
sally | 34
|
||||||
lita | 25
|
alex | 30
|
||||||
sharon | 25
|
cim | 30
|
||||||
denise | 24
|
sam | 30
|
||||||
jeff | 23
|
fred | 28
|
||||||
bill | 20
|
jean | 28
|
||||||
joe | 20
|
melissa | 28
|
||||||
linda | 19
|
nan | 28
|
||||||
sandra | 19
|
lita | 25
|
||||||
diane | 18
|
sharon | 25
|
||||||
edna | 18
|
denise | 24
|
||||||
gina | 18
|
jeff | 23
|
||||||
joan | 18
|
bill | 20
|
||||||
pat | 18
|
joe | 20
|
||||||
fanny | 8
|
linda | 19
|
||||||
mary | 8
|
sandra | 19
|
||||||
|
diane | 18
|
||||||
|
edna | 18
|
||||||
|
gina | 18
|
||||||
|
joan | 18
|
||||||
|
pat | 18
|
||||||
|
fanny | 8
|
||||||
|
mary | 8
|
||||||
(58 rows)
|
(58 rows)
|
||||||
|
|
||||||
|
|
|
@ -1,103 +1,126 @@
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,41 @@
|
||||||
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;
|
||||||
|
|
|
@ -1,271 +1,320 @@
|
||||||
QUERY: CREATE TABLE test_missing_target (a int, b int, c char(8), d char);
|
--
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
|
-- SELECT_IMPLICIT
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (1, 2, 'AAAA', 'b');
|
-- Test cases for queries with ordering terms missing from the target list.
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (2, 2, 'AAAA', 'c');
|
-- This used to be called "junkfilter.sql".
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
|
-- The parser uses the term "resjunk" to handle these cases.
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
|
-- - thomas 1998-07-09
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
|
--
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
|
-- load test data
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
|
CREATE TABLE test_missing_target (a int, b int, c char(8), d char);
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
|
INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
|
||||||
QUERY: INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
|
INSERT INTO test_missing_target VALUES (1, 2, 'AAAA', 'b');
|
||||||
QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c;
|
INSERT INTO test_missing_target VALUES (2, 2, 'AAAA', 'c');
|
||||||
c |count
|
INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
|
||||||
--------+-----
|
INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
|
||||||
AAAA | 2
|
INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
|
||||||
BBBB | 2
|
INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
|
||||||
CCCC | 2
|
INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
|
||||||
XXXX | 1
|
INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
|
||||||
bbbb | 1
|
INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
|
||||||
cccc | 2
|
-- w/ existing GROUP BY target
|
||||||
|
SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c;
|
||||||
|
c | count
|
||||||
|
----------+-------
|
||||||
|
AAAA | 2
|
||||||
|
BBBB | 2
|
||||||
|
CCCC | 2
|
||||||
|
XXXX | 1
|
||||||
|
bbbb | 1
|
||||||
|
cccc | 2
|
||||||
(6 rows)
|
(6 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c;
|
-- w/o existing GROUP BY target using a relation name in GROUP BY clause
|
||||||
count
|
SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c;
|
||||||
-----
|
count
|
||||||
2
|
-------
|
||||||
2
|
2
|
||||||
2
|
2
|
||||||
1
|
2
|
||||||
1
|
1
|
||||||
2
|
1
|
||||||
|
2
|
||||||
(6 rows)
|
(6 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) FROM test_missing_target GROUP BY a ORDER BY b;
|
-- w/o existing GROUP BY target and w/o existing a different ORDER BY target
|
||||||
|
-- failure expected
|
||||||
|
SELECT count(*) FROM test_missing_target GROUP BY a ORDER BY b;
|
||||||
ERROR: Attribute test_missing_target.b must be GROUPed or used in an aggregate function
|
ERROR: Attribute test_missing_target.b must be GROUPed or used in an aggregate function
|
||||||
QUERY: SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;
|
-- w/o existing GROUP BY target and w/o existing same ORDER BY target
|
||||||
count
|
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;
|
||||||
-----
|
count
|
||||||
1
|
-------
|
||||||
2
|
1
|
||||||
3
|
2
|
||||||
4
|
3
|
||||||
|
4
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT test_missing_target.b, count(*)
|
-- w/ existing GROUP BY target using a relation name in target
|
||||||
|
SELECT test_missing_target.b, count(*)
|
||||||
FROM test_missing_target GROUP BY b ORDER BY b;
|
FROM test_missing_target GROUP BY b ORDER BY b;
|
||||||
b|count
|
b | count
|
||||||
-+-----
|
---+-------
|
||||||
1| 1
|
1 | 1
|
||||||
2| 2
|
2 | 2
|
||||||
3| 3
|
3 | 3
|
||||||
4| 4
|
4 | 4
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT c FROM test_missing_target ORDER BY a;
|
-- w/o existing GROUP BY target
|
||||||
c
|
SELECT c FROM test_missing_target ORDER BY a;
|
||||||
--------
|
c
|
||||||
XXXX
|
----------
|
||||||
AAAA
|
XXXX
|
||||||
AAAA
|
AAAA
|
||||||
BBBB
|
AAAA
|
||||||
BBBB
|
BBBB
|
||||||
bbbb
|
BBBB
|
||||||
cccc
|
bbbb
|
||||||
cccc
|
cccc
|
||||||
CCCC
|
cccc
|
||||||
CCCC
|
CCCC
|
||||||
|
CCCC
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;
|
-- w/o existing ORDER BY target
|
||||||
count
|
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;
|
||||||
-----
|
count
|
||||||
4
|
-------
|
||||||
3
|
4
|
||||||
2
|
3
|
||||||
1
|
2
|
||||||
|
1
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) FROM test_missing_target ORDER BY 1 desc;
|
-- group using reference number
|
||||||
count
|
SELECT count(*) FROM test_missing_target ORDER BY 1 desc;
|
||||||
-----
|
count
|
||||||
10
|
-------
|
||||||
|
10
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY 1;
|
-- order using reference number
|
||||||
c |count
|
SELECT c, count(*) FROM test_missing_target GROUP BY 1;
|
||||||
--------+-----
|
c | count
|
||||||
AAAA | 2
|
----------+-------
|
||||||
BBBB | 2
|
AAAA | 2
|
||||||
CCCC | 2
|
BBBB | 2
|
||||||
XXXX | 1
|
CCCC | 2
|
||||||
bbbb | 1
|
XXXX | 1
|
||||||
cccc | 2
|
bbbb | 1
|
||||||
|
cccc | 2
|
||||||
(6 rows)
|
(6 rows)
|
||||||
|
|
||||||
QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY 3;
|
-- group using reference number out of range
|
||||||
|
-- failure expected
|
||||||
|
SELECT c, count(*) FROM test_missing_target GROUP BY 3;
|
||||||
ERROR: GROUP BY position 3 is not in target list
|
ERROR: GROUP BY position 3 is not in target list
|
||||||
QUERY: SELECT count(*) FROM test_missing_target x, test_missing_target y
|
-- group w/o existing GROUP BY and ORDER BY target under ambiguous condition
|
||||||
|
-- failure expected
|
||||||
|
SELECT count(*) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY b ORDER BY b;
|
GROUP BY b ORDER BY b;
|
||||||
ERROR: Column 'b' is ambiguous
|
ERROR: Column 'b' is ambiguous
|
||||||
QUERY: SELECT a, a FROM test_missing_target
|
-- order w/ target under ambiguous condition
|
||||||
|
-- failure NOT expected
|
||||||
|
SELECT a, a FROM test_missing_target
|
||||||
ORDER BY a;
|
ORDER BY a;
|
||||||
a|a
|
a | a
|
||||||
-+-
|
---+---
|
||||||
0|0
|
0 | 0
|
||||||
1|1
|
1 | 1
|
||||||
2|2
|
2 | 2
|
||||||
3|3
|
3 | 3
|
||||||
4|4
|
4 | 4
|
||||||
5|5
|
5 | 5
|
||||||
6|6
|
6 | 6
|
||||||
7|7
|
7 | 7
|
||||||
8|8
|
8 | 8
|
||||||
9|9
|
9 | 9
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
QUERY: SELECT a/2, a/2 FROM test_missing_target
|
-- order expression w/ target under ambiguous condition
|
||||||
|
-- failure NOT expected
|
||||||
|
SELECT a/2, a/2 FROM test_missing_target
|
||||||
ORDER BY a/2;
|
ORDER BY a/2;
|
||||||
?column?|?column?
|
?column? | ?column?
|
||||||
--------+--------
|
----------+----------
|
||||||
0| 0
|
0 | 0
|
||||||
0| 0
|
0 | 0
|
||||||
1| 1
|
1 | 1
|
||||||
1| 1
|
1 | 1
|
||||||
2| 2
|
2 | 2
|
||||||
2| 2
|
2 | 2
|
||||||
3| 3
|
3 | 3
|
||||||
3| 3
|
3 | 3
|
||||||
4| 4
|
4 | 4
|
||||||
4| 4
|
4 | 4
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
QUERY: SELECT a/2, a/2 FROM test_missing_target
|
-- group expression w/ target under ambiguous condition
|
||||||
|
-- failure NOT expected
|
||||||
|
SELECT a/2, a/2 FROM test_missing_target
|
||||||
GROUP BY a/2;
|
GROUP BY a/2;
|
||||||
?column?|?column?
|
?column? | ?column?
|
||||||
--------+--------
|
----------+----------
|
||||||
0| 0
|
0 | 0
|
||||||
1| 1
|
1 | 1
|
||||||
2| 2
|
2 | 2
|
||||||
3| 3
|
3 | 3
|
||||||
4| 4
|
4 | 4
|
||||||
(5 rows)
|
(5 rows)
|
||||||
|
|
||||||
QUERY: SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y
|
-- group w/ existing GROUP BY target under ambiguous condition
|
||||||
|
SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b;
|
GROUP BY x.b;
|
||||||
b|count
|
b | count
|
||||||
-+-----
|
---+-------
|
||||||
1| 1
|
1 | 1
|
||||||
2| 2
|
2 | 2
|
||||||
3| 3
|
3 | 3
|
||||||
4| 4
|
4 | 4
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) FROM test_missing_target x, test_missing_target y
|
-- group w/o existing GROUP BY target under ambiguous condition
|
||||||
|
SELECT count(*) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b;
|
GROUP BY x.b;
|
||||||
count
|
count
|
||||||
-----
|
-------
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(*) INTO TABLE test_missing_target2
|
-- group w/o existing GROUP BY target under ambiguous condition
|
||||||
FROM test_missing_target x, test_missing_target y
|
-- into a table
|
||||||
|
SELECT count(*) INTO TABLE test_missing_target2
|
||||||
|
FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b;
|
GROUP BY x.b;
|
||||||
QUERY: SELECT * FROM test_missing_target2;
|
SELECT * FROM test_missing_target2;
|
||||||
count
|
count
|
||||||
-----
|
-------
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT a%2, count(b) FROM test_missing_target GROUP BY test_missing_target.a%2;
|
-- Functions and expressions
|
||||||
?column?|count
|
-- w/ existing GROUP BY target
|
||||||
--------+-----
|
SELECT a%2, count(b) FROM test_missing_target GROUP BY test_missing_target.a%2;
|
||||||
0| 5
|
?column? | count
|
||||||
1| 5
|
----------+-------
|
||||||
|
0 | 5
|
||||||
|
1 | 5
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(c) FROM test_missing_target GROUP BY lower(test_missing_target.c);
|
-- w/o existing GROUP BY target using a relation name in GROUP BY clause
|
||||||
count
|
SELECT count(c) FROM test_missing_target GROUP BY lower(test_missing_target.c);
|
||||||
-----
|
count
|
||||||
2
|
-------
|
||||||
3
|
2
|
||||||
4
|
3
|
||||||
1
|
4
|
||||||
|
1
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(a) FROM test_missing_target GROUP BY a ORDER BY b;
|
-- w/o existing GROUP BY target and w/o existing a different ORDER BY target
|
||||||
|
-- failure expected
|
||||||
|
SELECT count(a) FROM test_missing_target GROUP BY a ORDER BY b;
|
||||||
ERROR: Attribute test_missing_target.b must be GROUPed or used in an aggregate function
|
ERROR: Attribute test_missing_target.b must be GROUPed or used in an aggregate function
|
||||||
QUERY: SELECT count(b) FROM test_missing_target GROUP BY b/2 ORDER BY b/2;
|
-- w/o existing GROUP BY target and w/o existing same ORDER BY target
|
||||||
count
|
SELECT count(b) FROM test_missing_target GROUP BY b/2 ORDER BY b/2;
|
||||||
-----
|
count
|
||||||
1
|
-------
|
||||||
5
|
1
|
||||||
4
|
5
|
||||||
|
4
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
QUERY: SELECT lower(test_missing_target.c), count(c)
|
-- w/ existing GROUP BY target using a relation name in target
|
||||||
|
SELECT lower(test_missing_target.c), count(c)
|
||||||
FROM test_missing_target GROUP BY lower(c) ORDER BY lower(c);
|
FROM test_missing_target GROUP BY lower(c) ORDER BY lower(c);
|
||||||
lower |count
|
lower | count
|
||||||
--------+-----
|
----------+-------
|
||||||
aaaa | 2
|
aaaa | 2
|
||||||
bbbb | 3
|
bbbb | 3
|
||||||
cccc | 4
|
cccc | 4
|
||||||
xxxx | 1
|
xxxx | 1
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
QUERY: SELECT a FROM test_missing_target ORDER BY upper(d);
|
-- w/o existing GROUP BY target
|
||||||
a
|
SELECT a FROM test_missing_target ORDER BY upper(d);
|
||||||
-
|
a
|
||||||
0
|
---
|
||||||
1
|
0
|
||||||
2
|
1
|
||||||
3
|
2
|
||||||
4
|
3
|
||||||
5
|
4
|
||||||
6
|
5
|
||||||
7
|
6
|
||||||
8
|
7
|
||||||
9
|
8
|
||||||
|
9
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(b) FROM test_missing_target
|
-- w/o existing ORDER BY target
|
||||||
|
SELECT count(b) FROM test_missing_target
|
||||||
GROUP BY (b + 1) / 2 ORDER BY (b + 1) / 2 desc;
|
GROUP BY (b + 1) / 2 ORDER BY (b + 1) / 2 desc;
|
||||||
count
|
count
|
||||||
-----
|
-------
|
||||||
7
|
7
|
||||||
3
|
3
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(x.a) FROM test_missing_target x, test_missing_target y
|
-- group w/o existing GROUP BY and ORDER BY target under ambiguous condition
|
||||||
|
-- failure expected
|
||||||
|
SELECT count(x.a) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY b/2 ORDER BY b/2;
|
GROUP BY b/2 ORDER BY b/2;
|
||||||
ERROR: Column 'b' is ambiguous
|
ERROR: Column 'b' is ambiguous
|
||||||
QUERY: SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
|
-- group w/ existing GROUP BY target under ambiguous condition
|
||||||
|
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b/2;
|
GROUP BY x.b/2;
|
||||||
?column?|count
|
?column? | count
|
||||||
--------+-----
|
----------+-------
|
||||||
0| 1
|
0 | 1
|
||||||
1| 5
|
1 | 5
|
||||||
2| 4
|
2 | 4
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
QUERY: SELECT count(b) FROM test_missing_target x, test_missing_target y
|
-- group w/o existing GROUP BY target under ambiguous condition
|
||||||
|
-- failure expected due to ambiguous b in count(b)
|
||||||
|
SELECT count(b) FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b/2;
|
GROUP BY x.b/2;
|
||||||
ERROR: Column 'b' is ambiguous
|
ERROR: Column 'b' is ambiguous
|
||||||
QUERY: SELECT count(x.b) INTO TABLE test_missing_target3
|
-- group w/o existing GROUP BY target under ambiguous condition
|
||||||
FROM test_missing_target x, test_missing_target y
|
-- into a table
|
||||||
|
SELECT count(x.b) INTO TABLE test_missing_target3
|
||||||
|
FROM test_missing_target x, test_missing_target y
|
||||||
WHERE x.a = y.a
|
WHERE x.a = y.a
|
||||||
GROUP BY x.b/2;
|
GROUP BY x.b/2;
|
||||||
QUERY: SELECT * FROM test_missing_target3;
|
SELECT * FROM test_missing_target3;
|
||||||
count
|
count
|
||||||
-----
|
-------
|
||||||
1
|
1
|
||||||
5
|
5
|
||||||
4
|
4
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
QUERY: DROP TABLE test_missing_target;
|
-- Cleanup
|
||||||
QUERY: DROP TABLE test_missing_target2;
|
DROP TABLE test_missing_target;
|
||||||
QUERY: DROP TABLE test_missing_target3;
|
DROP TABLE test_missing_target2;
|
||||||
|
DROP TABLE test_missing_target3;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
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;
|
||||||
|
|
|
@ -1,142 +1,151 @@
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,241 +1,249 @@
|
||||||
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
|
|
||||||
2
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
QUERY: SELECT 1 AS two UNION ALL SELECT 1;
|
|
||||||
two
|
|
||||||
---
|
|
||||||
1
|
|
||||||
1
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
QUERY: SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
|
|
||||||
three
|
|
||||||
-----
|
-----
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT 1 AS two UNION ALL SELECT 1;
|
||||||
|
two
|
||||||
|
-----
|
||||||
|
1
|
||||||
|
1
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
|
||||||
|
three
|
||||||
|
-------
|
||||||
|
1
|
||||||
|
2
|
||||||
|
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
|
|
||||||
2
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
QUERY: SELECT 1 AS two UNION ALL SELECT 1;
|
|
||||||
two
|
|
||||||
---
|
|
||||||
1
|
|
||||||
1
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
QUERY: SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
|
|
||||||
three
|
|
||||||
-----
|
-----
|
||||||
1
|
1.1
|
||||||
2
|
2
|
||||||
3
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT 1 AS two UNION ALL SELECT 1;
|
||||||
|
two
|
||||||
|
-----
|
||||||
|
1
|
||||||
|
1
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT 1 AS three UNION SELECT 2 UNION SELECT 3;
|
||||||
|
three
|
||||||
|
-------
|
||||||
|
1
|
||||||
|
2
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue