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 statement with one branch being null gives "Mismatch between schema and batches" #5733

Closed
mslapek opened this issue Mar 25, 2023 · 1 comment · Fixed by #5734
Closed
Labels
bug Something isn't working

Comments

@mslapek
Copy link
Contributor

mslapek commented Mar 25, 2023

Describe the bug

Case statement, where the first branch is NULL and another one is a number causes "Mismatch between schema and batches" error.

In batch schema, such column has Int32 datatype (or some similar).

In plan schema, such columns have an invalid datatype Null.

To Reproduce

Add this to the middle of pg_compat_union.slt:

statement ok
CREATE TABLE aggregate_test_100_nullable_by_sql AS
SELECT
    *,
    CASE
        WHEN c4 % 3 = 0 THEN NULL
        ELSE c5
    END AS n5,
    CASE
        WHEN c3 % 3 != 0 THEN c9
        ELSE NULL
    END AS n9
FROM aggregate_test_100_by_sql

Under Postgres this statement succeeds.

Expected behavior

To have the same behavior as Postgres: success.

Additional context

No response

@mslapek mslapek added the bug Something isn't working label Mar 25, 2023
@mslapek
Copy link
Contributor Author

mslapek commented Mar 26, 2023

As a workaround you can add CAST to the first branch of CASE:

CREATE TABLE aggregate_first_50_by_sql AS
SELECT
    *,
    CASE
        WHEN c4 % 3 = 0 THEN CAST(NULL AS INT)
        ELSE c5
    END AS n5
FROM aggregate_test_100_by_sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant