Support postgres omitted interval span unit #5930
Merged
+80
−5
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.
This PR adds support for handling postgres INTERVAL literal spans that omit the span units, both parsing and inferring the correct units for transpilation.
Examples
INTERVAL '1 00:01'
INTERVAL '1 00:01:01'
Context:
INTERVAL
sinterval literals generally consist of the word
INTERVAL
, a string literal like'6'
and a unit string likeDAYS
INTERVAL '6' DAYS
in many dialects you may specify compound units, which we parse into
exp.IntervalSpan
based on the presence of "TO"INTERVAL '163 12:39' DAY TO MINUTE
INTERVAL '163 12:39:59.1' DAY TO SECOND
Context: postgres
Postgres lets you omit the unit strings
DAY TO MINUTE
andDAY TO SECOND
if the second element in the literal is ahh:[mm:[ss[.ff]]]
INTERVAL '1 01:01:01.01'
INTERVAL '1 01:01:01'
INTERVAL '1 01:01'
INTERVAL '1.5 01:'
INTERVAL '-0.25 01:'
INTERVAL '1 01'
This issue
If the span unit is omitted, we incorrectly ingest the token following the literal because we assume it's a unit like
DAY
a > INTERVAL '1 00:00' AND TRUE
AND
so don't recognize the compound condition