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 range types #164

Open
vladfaust opened this issue Apr 13, 2019 · 7 comments
Open

Support range types #164

vladfaust opened this issue Apr 13, 2019 · 7 comments

Comments

@vladfaust
Copy link
Contributor

Currently:

require "pg"

db = DB.open("postgres://postgres:postgres@localhost:5432/postgres")
pp db.scalar("SELECT int4range(10, 20)") # => Bytes
@miketheman
Copy link
Contributor

I've been taking a stab at this, and can't seem to figure out where the "rules" for decoding a given message from Postgres wire format come from - @will any advice here?

@asterite
Copy link
Contributor

asterite commented Oct 9, 2019

@miketheman It's in https://github.com/will/crystal-pg/blob/master/src/pg/decoder.cr

Every postgres type has an ID, called oid. A decoder can handle a series of oids. So my guess is that you'll need to define a new Int4Range decoder and register it, but then you'll also want to define a Postgres::Range type, which is different than Crystal's Range.

(this is just from me fiddling with the library, I might be wrong)

@miketheman
Copy link
Contributor

@asterite Thanks - I got that far. I'm more interested in how to interpret the bytes returned from PG.

@will
Copy link
Owner

will commented Oct 9, 2019

The functions in postgres are usually ending in _send

Here is the range one I think: https://github.com/postgres/postgres/blob/b538c90b1bded5464787e2b8e4431302d24eb601/src/backend/utils/adt/rangetypes.c#L246

@will
Copy link
Owner

will commented Oct 9, 2019

You can also call them as functions in postgres if that helps playing around with things faster:

will=# select range_send('[1,3]'::int4range);
              range_send
--------------------------------------
 \x0200000004000000010000000400000004
(1 row)

miketheman added a commit to miketheman/crystal-pg that referenced this issue Oct 9, 2019
This is an exploratory effort to support will#164

It is not ready for merging, but I wanted to to open it for discussion
and review.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
miketheman added a commit to miketheman/crystal-pg that referenced this issue Oct 9, 2019
This is an exploratory effort to support will#164

It is not ready for merging, but I wanted to to open it for discussion
and review.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@miketheman
Copy link
Contributor

I started a Draft PR for discussion.

@pascalbetz
Copy link

pascalbetz commented Oct 2, 2020

I can work on this, if it is stalled.
Got a prototype working, need some guidance though.

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

No branches or pull requests

5 participants