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

Support for 'infinity' timestamps #690

Closed
yrashk opened this issue Nov 18, 2024 · 2 comments · Fixed by #746
Closed

Support for 'infinity' timestamps #690

yrashk opened this issue Nov 18, 2024 · 2 comments · Fixed by #746
Labels
bug Something isn't working

Comments

@yrashk
Copy link

yrashk commented Nov 18, 2024

Postgres supports infinity timestamps.

=# select 'infinity'::timestamptz;
 timestamptz 
-------------
 infinity
(1 row)

However, this adapter doesn't:

CleanShot 2024-11-18 at 09 18 43@2x

It is, however, a valid and useful range to support, particularly in the context of temporal tables.

@tconbeer
Copy link
Owner

Interesting. I actually think this is a problem with Harlequin core, or more specifically, the data table implementation. We use Apache Arrow to store the data returned by the query, and I don't think Arrow supports infinity timestamps (they have an Arrow.max constant, I believe). We probably just need to catch this error and replace the infinity value with Arrow.max.

@tconbeer tconbeer changed the title Support for 'infinity' Support for 'infinity' timestamps Nov 18, 2024
@tconbeer tconbeer added the bug Something isn't working label Nov 18, 2024
@tconbeer tconbeer transferred this issue from tconbeer/harlequin-postgres Nov 18, 2024
@tconbeer
Copy link
Owner

tconbeer commented Feb 5, 2025

Turns out this error is a "feature" of psycopg3: https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#no-default-infinity-dates-handling

For comparison, duckdb also supports infinity timestamps, and while the fetch_arrow_table() behavior is a little confusing, it looks like it uses the target data type's max value (datetime.max, numpy.max, or arrow.max):

>>> cur  = duckdb.execute("select 'infinity'::timestamp as foo")
>>> cur.fetchall()
[(datetime.datetime(9999, 12, 31, 23, 59, 59, 999999),)]

>>> cur2 = duckdb.execute("select 'infinity'::timestamp as foo")
>>> tab = cur2.fetch_arrow_table()
>> tab
pyarrow.Table
foo: timestamp[us]
----
foo: [[<value out of range: 9223372036854775807>]]
>>> tab[0][0]
<pyarrow.TimestampScalar: '32103-01-10T04:00:54.775807'>

>>> cur3 = duckdb.execute("select 'infinity'::timestamp as foo")
>>> cur3.fetchnumpy()
{'foo': array(['294247-01-10T04:00:54.775807'], dtype='datetime64[us]')}

I think that's the better experience, so I'm going to do that, and then also probably render the max timestamps as infinity or something in the data table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants