diff options
author | udovichenko-r <udovichenko-r@yandex-team.com> | 2024-11-19 14:11:52 +0300 |
---|---|---|
committer | udovichenko-r <udovichenko-r@yandex-team.com> | 2024-11-19 14:22:01 +0300 |
commit | 72b3cd51dc3fb9d16975d353ea82fd85701393cc (patch) | |
tree | 318141940b8bf6bdb37ad6154e745e2ebfe3613f /yql/essentials/tests/postgresql/cases/select_having.out | |
parent | 223625eed56ec3e2808c010eac46dba1c9a64d13 (diff) | |
download | ydb-72b3cd51dc3fb9d16975d353ea82fd85701393cc.tar.gz |
YQL-19206 Move contrib/ydb/library/yql/tests/postgresql -> yql/essentials/tests/postgresql
commit_hash:46fdf59714b20cf2b61233a06e58365227d3c8b2
Diffstat (limited to 'yql/essentials/tests/postgresql/cases/select_having.out')
-rw-r--r-- | yql/essentials/tests/postgresql/cases/select_having.out | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/yql/essentials/tests/postgresql/cases/select_having.out b/yql/essentials/tests/postgresql/cases/select_having.out new file mode 100644 index 0000000000..e8be510b01 --- /dev/null +++ b/yql/essentials/tests/postgresql/cases/select_having.out @@ -0,0 +1,84 @@ +-- +-- SELECT_HAVING +-- +-- load test data +CREATE TABLE test_having (a int, b int, c char(8), d char); +INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A'); +INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b'); +INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c'); +INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D'); +INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e'); +INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F'); +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 ORDER BY b, c; + b | c +---+---------- + 1 | XXXX + 3 | bbbb +(2 rows) + +-- HAVING is effectively equivalent to WHERE in this case +SELECT b, c FROM test_having + GROUP BY b, c HAVING b = 3 ORDER BY b, c; + b | c +---+---------- + 3 | BBBB + 3 | bbbb +(2 rows) + +SELECT lower(c), count(c) FROM test_having + GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a) + ORDER BY lower(c); + lower | count +-------+------- + bbbb | 3 + cccc | 4 + xxxx | 1 +(3 rows) + +SELECT c, max(a) FROM test_having + GROUP BY c HAVING count(*) > 2 OR min(a) = max(a) + ORDER BY c; + c | max +----------+----- + XXXX | 0 + bbbb | 5 +(2 rows) + +-- test degenerate cases involving HAVING without GROUP BY +-- Per SQL spec, these should generate 0 or 1 row, even without aggregates +SELECT min(a), max(a) FROM test_having HAVING min(a) = max(a); + min | max +-----+----- +(0 rows) + +SELECT min(a), max(a) FROM test_having HAVING min(a) < max(a); + min | max +-----+----- + 0 | 9 +(1 row) + +-- the really degenerate case: need not scan table at all +SELECT 1 AS one FROM test_having HAVING 1 > 2; + one +----- +(0 rows) + +SELECT 1 AS one FROM test_having HAVING 1 < 2; + one +----- + 1 +(1 row) + +-- and just to prove that we aren't scanning the table: +SELECT 1 AS one FROM test_having WHERE 1/a = 1 HAVING 1 < 2; + one +----- + 1 +(1 row) + +DROP TABLE test_having; |