Sequel chokes on infinity timestamp #454

Closed
mattsoldo opened this Issue Mar 17, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@mattsoldo

I'm trying the following, but sequel doesn't like it. Works fine directly in psql:

in ruby

>> u = User.fetch("select 'infinity'::timestamp - '1 month'::interval")
=> #<Sequel::Postgres::Dataset: "select 'infinity'::timestamp - '1 month'::interval"> 
>> u.first
Sequel::InvalidValue: ArgumentError: no time information in "infinity"

in psql

=> select 'infinity'::timestamp - '1 month'::interval;
 ?column? 
----------
 infinity
(1 row)
@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans Mar 17, 2012

Owner

How do you think Sequel should handle this? I don't think either Time or DateTime can handle infinity timestamps. Do you want something similar to the MySQL invalid date support, where you can choose to return such timestamps as nil or as a string?

As a workaround, you could probably override Time.parse/DateTime.parse to specially recognize 'infinity' and handle it as you consider appropriate.

Owner

jeremyevans commented Mar 17, 2012

How do you think Sequel should handle this? I don't think either Time or DateTime can handle infinity timestamps. Do you want something similar to the MySQL invalid date support, where you can choose to return such timestamps as nil or as a string?

As a workaround, you could probably override Time.parse/DateTime.parse to specially recognize 'infinity' and handle it as you consider appropriate.

@mattsoldo

This comment has been minimized.

Show comment Hide comment
@mattsoldo

mattsoldo Mar 17, 2012

I'm not entirely sure of the right way to handle it, but it would be great if it could return something. Returning a nil would be just fine. The query is valid in Postgres, and it turns out to be very useful for certain things (i.e. when subtracting two timestamps, if the "end" time is set to infinity, then the duration equals infinity, which guarantees that it is greater than all finite durations).

It looks like AR has similarly considered this issue (rails/rails#544).

I'm not entirely sure of the right way to handle it, but it would be great if it could return something. Returning a nil would be just fine. The query is valid in Postgres, and it turns out to be very useful for certain things (i.e. when subtracting two timestamps, if the "end" time is set to infinity, then the duration equals infinity, which guarantees that it is greater than all finite durations).

It looks like AR has similarly considered this issue (rails/rails#544).

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans Mar 17, 2012

Owner

AR appears to use an infinite float. I'm not sure I like that approach, but it makes sense on some level. I'll probably given an option for nil, float, or string, similar to the MySQL invalid date support. Should have something committed early next week.

Owner

jeremyevans commented Mar 17, 2012

AR appears to use an infinite float. I'm not sure I like that approach, but it makes sense on some level. I'll probably given an option for nil, float, or string, similar to the MySQL invalid date support. Should have something committed early next week.

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans Mar 18, 2012

Owner

I'll probably be committing the patch at http://pastie.org/3618712 on Monday, after running it through the full test suite. If anyone wants to review that patch and give me feedback, I'd appreciate it.

Owner

jeremyevans commented Mar 18, 2012

I'll probably be committing the patch at http://pastie.org/3618712 on Monday, after running it through the full test suite. If anyone wants to review that patch and give me feedback, I'd appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment