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

feat: UNION ALL should cast input columns to least restrictive types #7768

Open
Tracked by #7577
algosday opened this issue Feb 8, 2023 · 3 comments
Open
Tracked by #7577
Assignees
Labels
component/frontend Protocol, parsing, binder. type/bug Something isn't working

Comments

@algosday
Copy link
Contributor

algosday commented Feb 8, 2023

Describe the bug

A simple SQL query produces an error in RW but works fine in PostgreSQL. This SQL statement is generated by dbt as an example.

This bug is not blocking #7577 but will prevent our users from completing the dbt getting started guide.

To Reproduce

Execute the following SQL on RW.

select 1 as id
    union all
    select null as id;

Got an error,

Query 1 ERROR: ERROR:  QueryError: Invalid input syntax: UNION types INT32 of column id is different from types VARCHAR of column id

Expected behavior

It should execute successfully and produce a result.

id
----
1
NULL

( PostgreSQL 14.6 )

Additional context

No response

@algosday algosday added type/bug Something isn't working component/frontend Protocol, parsing, binder. labels Feb 8, 2023
@github-actions github-actions bot added this to the release-0.1.17 milestone Feb 8, 2023
@xiangjinwu
Copy link
Contributor

PostgreSQL's rule is inconsistent between select and values:

test=# select 1 union all select null;
 ?column? 
----------
        1
         
(2 rows)

test=# select 1 union all values (null);
ERROR:  UNION types integer and text cannot be matched

We will need to handle each case differently.

@xiangjinwu
Copy link
Contributor

Oops, we have not supported align_types even when union int and smallint:

dev=> select 1 union all select 2::smallint;
ERROR:  QueryError: Invalid input syntax: UNION types INT32 of column ?column? is different from types INT16 of column int2

@xiangjinwu xiangjinwu changed the title QueryError: Invalid input syntax: UNION types INT32 of column id is different from types VARCHAR of column id UNION ALL should cast input columns to least restrictive types Feb 8, 2023
@xiangjinwu xiangjinwu modified the milestones: release-0.18, release-0.19 Mar 20, 2023
@xiangjinwu xiangjinwu changed the title UNION ALL should cast input columns to least restrictive types feat: UNION ALL should cast input columns to least restrictive types Apr 24, 2023
@xiangjinwu xiangjinwu modified the milestones: release-0.19, release-0.20 Apr 26, 2023
@xiangjinwu
Copy link
Contributor

select union select has been supported by #11452 but there are more cases, so keeping this issue open

  • values union values: values (1) union values (1.2);
  • union union select: select 1 union all select 2 union all select 1.5;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/frontend Protocol, parsing, binder. type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants