Skip to content

Conversation

shah-nirmit
Copy link
Contributor

@shah-nirmit shah-nirmit commented Mar 19, 2025

Fixes #601

Signed-off-by: Nirmit Shah <nirmitshah191@gmail.com>
@shah-nirmit
Copy link
Contributor Author

shah-nirmit commented Mar 19, 2025

@JelteF Is this the type of output we expect when selecting a union datatype column?
Also Can you help with some examples of how union_extract and union_tag functions will be used with the datatypes? Some sample queries...

Signed-off-by: Nirmit Shah <nirmitshah191@gmail.com>
Signed-off-by: Nirmit Shah <nirmitshah191@gmail.com>
@shah-nirmit shah-nirmit marked this pull request as ready for review March 19, 2025 09:56
@JelteF
Copy link
Collaborator

JelteF commented Mar 19, 2025

Yes, that looks great. I think we should at least support the following:

select union_extract(r['u'], 'str') from duckdb.query($$ select * from tbl1 $$) r;
select union_tag(r['u']) from duckdb.query($$ select * from tbl1 $$) r;

This would also be nice, but since duckdb doesn't support indexing a union this way I think that will be impossible to do, without changes to DuckDB.

select r['u']['str'] from duckdb.query($$ select * from tbl1 $$) r;

I think you could in theory implement the following syntax without changes to duckdb. But I think a better way would be to add index support for unions to duckdb itself:

select r['u']::duckdb.union['str'] from duckdb.query($$ select * from tbl1 $$) r;

Finally since postgres doesn't support overloading the . operator it's impossible to implement support for the following syntax without changes to DuckDB:

select r['u'].str from duckdb.query($$ select * from tbl1 $$) r;

@shah-nirmit
Copy link
Contributor Author

shah-nirmit commented Mar 19, 2025

Yes, that looks great. I think we should at least support the following:

select union_extract(r['u'], 'str') from duckdb.query($$ select * from tbl1 $$) r;
select union_tag(r['u']) from duckdb.query($$ select * from tbl1 $$) r;

This would also be nice, but since duckdb doesn't support indexing a union this way I think that will be impossible to do, without changes to DuckDB.

select r['u']['str'] from duckdb.query($$ select * from tbl1 $$) r;

I think you could in theory implement the following syntax without changes to duckdb. But I think a better way would be to add index support for unions to duckdb itself:

select r['u']::duckdb.union['str'] from duckdb.query($$ select * from tbl1 $$) r;

Finally since postgres doesn't support overloading the . operator it's impossible to implement support for the following syntax without changes to DuckDB:

select r['u'].str from duckdb.query($$ select * from tbl1 $$) r;

I think the first syntax is the most straigth forward , and have implemented that and updated output in PR description...

@shah-nirmit shah-nirmit changed the title [WIP] Add Support for DuckDB UNION type Add Support for DuckDB UNION type Mar 19, 2025
Signed-off-by: Nirmit Shah <nirmitshah191@gmail.com>
@shah-nirmit shah-nirmit requested a review from JelteF March 20, 2025 08:26
@JelteF JelteF merged commit 91b6bb1 into duckdb:main Mar 20, 2025
6 checks passed
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

Successfully merging this pull request may close these issues.

Support DuckDB UNION type
2 participants