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(duckdb): add support for the UNION type #4128

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4154,6 +4154,7 @@ class Type(AutoName):
UINT256 = auto()
UMEDIUMINT = auto()
UDECIMAL = auto()
UNION = auto()
UNIQUEIDENTIFIER = auto()
UNKNOWN = auto() # Sentinel value, useful for type annotation
USERDEFINED = "USER-DEFINED"
Expand All @@ -4172,6 +4173,7 @@ class Type(AutoName):
Type.NESTED,
Type.OBJECT,
Type.STRUCT,
Type.UNION,
}

ARRAY_TYPES = {
Expand Down
2 changes: 2 additions & 0 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Parser(metaclass=_Parser):
TokenType.NESTED,
TokenType.OBJECT,
TokenType.STRUCT,
TokenType.UNION,
}

NESTED_TYPE_TOKENS = {
Expand Down Expand Up @@ -522,6 +523,7 @@ class Parser(metaclass=_Parser):
*TYPE_TOKENS,
*NO_PAREN_FUNCTIONS,
}
ID_VAR_TOKENS.remove(TokenType.UNION)
georgesittas marked this conversation as resolved.
Show resolved Hide resolved

INTERVAL_VARS = ID_VAR_TOKENS - {TokenType.END}

Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def test_duckdb(self):
parse_one("a // b", read="duckdb").assert_is(exp.IntDiv).sql(dialect="duckdb"), "a // b"
)

self.validate_identity("CREATE TABLE tbl1 (u UNION(num INT, str TEXT))")
self.validate_identity("INSERT INTO x BY NAME SELECT 1 AS y")
self.validate_identity("SELECT 1 AS x UNION ALL BY NAME SELECT 2 AS x")
self.validate_identity("SELECT SUM(x) FILTER (x = 1)", "SELECT SUM(x) FILTER(WHERE x = 1)")
Expand Down
Loading