Repository navigation
fix(semantics): type DuckDB JSON casts, to_json, AT TIME ZONE and TO_TIMESTAMP - #168
Merged
Merged
Conversation
…TIMESTAMP DuckDB type inference left a cast to JSON, to_json and AT TIME ZONE untyped, and gave TO_TIMESTAMP of a number the type TIMESTAMP. DuckDB 2.0.0 types the first two JSON, flips AT TIME ZONE between TIMESTAMP and TIMESTAMPTZ, and returns TIMESTAMPTZ from TO_TIMESTAMP. Each is now typed as the engine types it; AT TIME ZONE over any other operand stays unknown.
DuckDB's TIMESTAMP holds microseconds; TIMESTAMP(0), (3) and (9) are TIMESTAMP_S, TIMESTAMP_MS and TIMESTAMP_NS, and AT TIME ZONE over them gives TIMESTAMPTZ_NS. A cast to any precision but 6 was typed TIMESTAMP, which AT TIME ZONE now turns into a wrong TIMESTAMPTZ. Such casts stay unknown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
DuckDB type inference got four expressions wrong. A cast to JSON (
CAST(x AS JSON),x::JSON),to_json(...)andx AT TIME ZONE zhad no inferred type.TO_TIMESTAMP(<number>)was inferred as TIMESTAMP, but DuckDB returns TIMESTAMPTZ. Callers that compare declared types with inferred ones reported these columns as unproven.Changes
to_jsonare typed JSON. A cast toJSON[]is typedJSON[].AT TIME ZONEandtimezone(z, x)turn TIMESTAMP into TIMESTAMPTZ and TIMESTAMPTZ into TIMESTAMP. Any other or unknown operand stays unknown.TO_TIMESTAMPwith one argument is TIMESTAMPTZ.TIMESTAMP(p)with p other than 6 stays unknown. DuckDB types it TIMESTAMP_S, _MS or _NS, and AT TIME ZONE over it gives TIMESTAMPTZ_NS.Verification
typeof.DESCRIBEof each converted statement agrees on all 786.cargo test -p sqlquack-semantics --all-features,make check-cimake verify-recorded: 0 failed, and translation results and SQL sizes are unchanged.