Details
Description
Given the following, minimal sample:
CREATE SCHEMA A ; |
|
CREATE TABLE A.A ( A BOOLEAN DEFAULT TRUE); |
|
SELECT 1 AS A FROM A.A AS AA HAVING TRUE; |
Summary: No result is returned if a constant without aggregate function is selected and a HAVING clause (with a constant expression like 'TRUE'), without an explicit GROUP BY clause is used on an empty table.
I expect that a single 1 is returned. This is also the behaviour of Postgres and described here (https://stackoverflow.com/a/53238082). The HAVING groups the empty result into a single, but existing group. HAVING doesn't filter this single row, so a single row and result should be returned.
When a explicit GROUP BY is used, or COUNT ( * ) is used additionally, or there exists an entry in the table, a 1 is returned, which is correct.
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Description |
Given the following, minimal sample:
{code:sql} CREATE SCHEMA A ; CREATE TABLE A.A ( A BOOLEAN DEFAULT TRUE); SELECT 1 AS A FROM A.A AS AA HAVING TRUE; {code} Summary: No result is returned if a constant without aggregate function is selected and a HAVING clause (with a constant expression like 'TRUE'), without an explicit GROUP BY clause is used on an empty table. I expect that a single 1 is returned. This is also the behaviour of Postgres and described here (https://stackoverflow.com/a/53238082). The HAVING groups the empty result into a single, but existing group. HAVING doesn't filter this single row, so a single row and result should be returned. When a explicit GROUP BY is used, or COUNT(*) is used additionally, or there exists an entry in the table, a 1 is returned, which is correct. |
Given the following, minimal sample:
{code:sql} CREATE SCHEMA A ; CREATE TABLE A.A ( A BOOLEAN DEFAULT TRUE); SELECT 1 AS A FROM A.A AS AA HAVING TRUE; {code} Summary: No result is returned if a constant without aggregate function is selected and a HAVING clause (with a constant expression like 'TRUE'), without an explicit GROUP BY clause is used on an empty table. I expect that a single 1 is returned. This is also the behaviour of Postgres and described here (https://stackoverflow.com/a/53238082). The HAVING groups the empty result into a single, but existing group. HAVING doesn't filter this single row, so a single row and result should be returned. When a explicit GROUP BY is used, or COUNT ( * ) is used additionally, or there exists an entry in the table, a 1 is returned, which is correct. |
Fix Version/s | 10.4 [ 22408 ] | |
Affects Version/s | 5.5 [ 15800 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 10.2 [ 14601 ] | |
Affects Version/s | 10.3 [ 22126 ] | |
Affects Version/s | 10.4 [ 22408 ] | |
Assignee | Igor Babaev [ igor ] | |
Priority | Major [ 3 ] | Minor [ 4 ] |
Workflow | MariaDB v3 [ 97285 ] | MariaDB v4 [ 141322 ] |
Affects Version/s | 10.5 [ 23123 ] | |
Affects Version/s | 10.6 [ 24028 ] | |
Affects Version/s | 10.7 [ 24805 ] | |
Affects Version/s | 10.8 [ 26121 ] | |
Affects Version/s | 10.9 [ 26905 ] | |
Affects Version/s | 10.10 [ 27530 ] |
Fix Version/s | 10.3 [ 22126 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Fix Version/s | 10.6 [ 24028 ] | |
Fix Version/s | 10.7 [ 24805 ] | |
Fix Version/s | 10.8 [ 26121 ] | |
Fix Version/s | 10.9 [ 26905 ] |
Labels | optimizer | 11.0-sel optimizer |
Assignee | Igor Babaev [ igor ] | Michael Widenius [ monty ] |
Fix Version/s | 10.7 [ 24805 ] |
Fix Version/s | 10.3 [ 22126 ] |
Fix Version/s | 10.8 [ 26121 ] |
Fix Version/s | 10.9 [ 26905 ] |
Fix Version/s | 10.4 [ 22408 ] |
Indeed, PostgreSQL returns a result:
postgres=#
postgres=#
a
---
1
(1 row)
All versions of MariaDB and MySQL return an empty set.
I don't know which is correct.