Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASE <column> WHEN NULL THEN 0 ELSE 1 END returns wrong result #6124

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

CASE <column> WHEN NULL THEN 0 ELSE 1 END returns wrong result #6124

monetdb-team opened this issue Nov 30, 2020 · 0 comments

Comments

@monetdb-team
Copy link

@monetdb-team monetdb-team commented Nov 30, 2020

Date: 2016-11-17 14:37:34 +0100
From: Martin van Dinther <<martin.van.dinther>>
To: SQL devs <>
Version: 11.23.13 (Jun2016-SP2)
CC: @njnes

Last updated: 2016-12-21 13:06:56 +0100

Comment 24698

Date: 2016-11-17 14:37:34 +0100
From: Martin van Dinther <<martin.van.dinther>>

User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0
Build Identifier:

CASE WHEN NULL THEN 0 ELSE 1 END
returns different result from equivalent:
CASE WHEN IS NULL THEN 0 ELSE 1 END

Reproducible: Always

Steps to Reproduce:

  1. start mserver5 (MonetDB 5 server v11.23.14)
  2. start mclient
  3. execute SQLs:
    CREATE TABLE table_two (this_column INTEGER);
    INSERT INTO table_two VALUES (1);
    INSERT INTO table_two VALUES (2);
    INSERT INTO table_two VALUES (null);
    SELECT * FROM table_two;
    SELECT this_column, (CASE WHEN this_column IS NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
    -- correct output
    SELECT this_column, (CASE this_column WHEN NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
    -- incorrect output for the NULL case
    DROP TABLE table_two;

Actual Results:

Welcome to mclient, the MonetDB/SQL interactive terminal (unreleased)
Database: MonetDB v11.23.14 (unreleased), 'demo'
Type \q to quit, ? for a list of available commands
auto commit mode: on
sql>CREATE TABLE table_two (this_column INTEGER);
operation successful (30.384ms)
sql>INSERT INTO table_two VALUES (1);
1 affected row (7.501ms)
sql>INSERT INTO table_two VALUES (2);
1 affected row (8.050ms)
sql>INSERT INTO table_two VALUES (null);
1 affected row (8.038ms)
sql>SELECT * FROM table_two;
+-------------+
| this_column |
+=============+
| 1 |
| 2 |
| null |
+-------------+
3 tuples (0.475ms)
sql>SELECT this_column, (CASE WHEN this_column IS NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
+-------------+------------+
| this_column | new_column |
+=============+============+
| 1 | 1 |
| 2 | 1 |
| null | 0 |
+-------------+------------+
3 tuples (0.680ms)
sql>-- correct output
sql>SELECT this_column, (CASE this_column WHEN NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
+-------------+------------+
| this_column | new_column |
+=============+============+
| 1 | 1 |
| 2 | 1 |
| null | 1 |
+-------------+------------+
3 tuples (1.140ms)
sql>-- incorrect output for the NULL case
sql>DROP TABLE table_two;
operation successful (11.339ms)

Expected Results:

sql>SELECT this_column, (CASE WHEN this_column IS NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
+-------------+------------+
| this_column | new_column |
+=============+============+
| 1 | 1 |
| 2 | 1 |
| null | 0 |
+-------------+------------+
3 tuples (0.680ms)

sql>SELECT this_column, (CASE this_column WHEN NULL THEN 0 ELSE 1 END) AS new_column FROM table_two;
+-------------+------------+
| this_column | new_column |
+=============+============+
| 1 | 1 |
| 2 | 1 |
| null | 0 |
+-------------+------------+
3 tuples (1.140ms)

Comment 24699

Date: 2016-11-17 15:34:11 +0100
From: MonetDB Mercurial Repository <>

Changeset 1947e5ba7370 made by Martin van Dinther martin.van.dinther@monetdbsolutions.com in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=1947e5ba7370

Changeset description:

Add test script for Bug #6124

Comment 24751

Date: 2016-12-03 12:08:11 +0100
From: MonetDB Mercurial Repository <>

Changeset b72b05357cdd made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=b72b05357cdd

Changeset description:

fixes for bugs 6124, 6125 and 6121
The apply rename optimizer step has been rewriten.
Apply optimizer now create new relational operators (doesn't steal
the structures, ie safe against referenced subqueries).

Comment 24754

Date: 2016-12-03 15:01:44 +0100
From: @njnes

when NULL != when IS NULL. The output output is correct, ie NULL IS NULL == TRUE while NULL != NULL == TRUE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant