Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Handle full timestamp ranges for redshift, postgres #787

Merged
merged 1 commit into from
Nov 30, 2023
Merged

Conversation

dlawin
Copy link
Contributor

@dlawin dlawin commented Nov 29, 2023

Update redshift/postgres normalize_timestamp to handle all possible values
https://www.postgresql.org/docs/current/datatype-datetime.html

  • Technically rounds BC timestamps the wrong way
  • Edge case at the upper/lower bounds, rounded to keep below overflow
    • the least() and greatest()

Resolves #786

@dlawin dlawin force-pushed the issue_786 branch 2 times, most recently from 0ec8b45 to 444d0a9 Compare November 30, 2023 00:44
@dlawin dlawin changed the title out of range temporal cols as UnknownColType Handle full timestamp ranges for redshift, postgres Nov 30, 2023
@dlawin
Copy link
Contributor Author

dlawin commented Nov 30, 2023

example query:

SELECT "id"::varchar, CASE WHEN "timestamp_value" IS NULL THEN NULL ELSE  RPAD(LEFT(left(to_char(least('294276-12-31 23:59:59.0000'::timestamp, greatest('4713-01-01 00:00:00.00
                  BC'::timestamp(6), least('294276-12-31 23:59:59.0000'::timestamp(6), "timestamp_value"::timestamp(6))))+ interval '0.0000005', 'YYYY-mm-dd
                  HH24:MI:SS.US'),length(to_char(least('294276-12-31 23:59:59.0000'::timestamp, greatest('4713-01-01 00:00:00.00 BC'::timestamp(6), least('294276-12-31 23:59:59.0000'::timestamp(6),
                  "timestamp_value"::timestamp(6))))+ interval '0.0000005', 'YYYY-mm-dd HH24:MI:SS.US')) - (6-6)), 26), 26, '0') END FROM "dev_dan"."timestamp_test_cases" WHERE ("id" >= 1) AND ("id"
                  < 12)

@dlawin dlawin merged commit b16252c into master Nov 30, 2023
6 checks passed
@dlawin dlawin deleted the issue_786 branch November 30, 2023 20:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redshift normalize_timestamp - Output timestamp out of range in EXTRACT()
3 participants