On Friday, April 22, 2016 at 6:58:02 AM UTC+3, Steve H wrote:
>
> Hi sequel fans,
>
> Given a custom Range:
>
>     CREATE TYPE timerange AS range (subtype = time);
>
> I'm trying to have a Sequel database with the `pg_range` and `pg_array` 
> extensions correctly deserialize a `timerange[]` array of ranges of times.
>
> Disregarding the question of how to look up the oid, here's what I have:
>
>     SELECT oid, typname FROM pg_type WHERE typname LIKE '%timerange%';
>
>     oid       typname
>     4242529   timerange
>     4242530   _timerange
>
> with this code:
>
>     type = :timerange
>     time_oid = 1183 # time without time zone
>     range_oid = 4242529
>     array_oid = range_oid + 1
>
>     Sequel::Postgres::PGRange.register(type, oid: range_oid, subtype_oid: 
> time_oid)
>     Sequel::Postgres::PGArray.register(type, oid: array_oid, scalar_oid: 
> range_oid, scalar_typecast: type)
>
> Any pointers on how to get this to work? I'm expecting to end up with:
>
>     PGArray[PGRange(SqlTime..SqlTime)..PGRange(SqlTime..SqlTime)]
>

I think you need to manually call DB.reset_conversion_procs after running 
the above code, then it should work

Second question: what's the best way to register these by name rather than 
> oid?
>

We would probably want to add a way to register Database-specific range 
types, which the pg_range extension doesn't currently support as you are 
the first person to express a need for it (just-in-time development!). 
 Something like:

  DB.register_range_type('timerange', :subtype_oid=>time_oid)

If you want to send in a pull request for that, that would be great, 
otherwise I'll try to implement it next week.  If you are looking into how 
to implement it, check out the commit history on the pg_array extension, it 
had similar changes made to it a few years back.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to