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

[bug?] UNION operation with different datatypes doesn't fail. #7011

Closed
2 tasks done
wtfzambo opened this issue Apr 9, 2023 · 2 comments
Closed
2 tasks done

[bug?] UNION operation with different datatypes doesn't fail. #7011

wtfzambo opened this issue Apr 9, 2023 · 2 comments

Comments

@wtfzambo
Copy link

wtfzambo commented Apr 9, 2023

What happens?

I'm not sure if this is actually a bug or a feature, but I noticed that when UNIONing two tables with same columns that may have different data types, duckdb successfully completes the union and re-casts the incompatible columns to a compatible data type if there is one.

To be fair I'm not complaining, I actually find this quite convenient for what I'm doing, but I thought it was right to report.

To Reproduce

data = [
    [None, 1, 'a', None],
    ['foo', 2, 'b', None],
    ['bar', 3.0, 42, {'foo': 'bar'}]
]

cols = ['col1', 'col2', 'col3', 'col4']

df = pd.DataFrame(data, columns=cols)
head = df.head(0)
duckdb.sql('SELECT * FROM head UNION SELECT * FROM df')

OS:

Windows 11 Home x64

DuckDB Version:

0.7.1

DuckDB Client:

Python 3.10

Full Name:

Federico Zambelli

Affiliation:

Vinhood

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree
@Mytherin
Copy link
Collaborator

Thanks for the report! This is indeed not a bug but intended behavior - if the types of a union do not match casts are added to compatible types if possible according to the implicit cast rules in the system, see here for more information.

@wtfzambo
Copy link
Author

Fantastic, thanks for the explanation! I missed that in the docs as I was looking in the "set operations" part.

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

No branches or pull requests

2 participants