brianc / node-pg-types

Type parsing for node-postgres
270 stars 55 forks source link

Interested in Range Types? #30

Closed jrf0110 closed 8 years ago

jrf0110 commented 9 years ago

I needed daterange parsing, so I created a module:

https://github.com/goodybag/pg-range-parser

If it were used in node-pg-types, I would go ahead and parse the underlying datatype if needed (like if it were integers).

bendrucker commented 9 years ago

Do range types return a specific oid that can be matched to a range of another oid?

jrf0110 commented 9 years ago

Unfortunately, it's not quite that nice (each specific range type has its own oid and no indication from pg_type as to what the base type is). But, node-pg-types could at least be intelligent about parsing the innards of the built-in range types http://www.postgresql.org/docs/9.3/static/rangetypes.html - parsing numbers and timestamps

bendrucker commented 9 years ago

Well we can support range types then. I've been naming these packages postgres-${type}. If you wanna work with me on getting it consistent with the rest of the parsers we can land this as part of my rewrite of pg-types.

jrf0110 commented 9 years ago

Since my module isn't for parsing any particular range type, but rather focuses on the range semantics (the start/end values are simply strings), would it still jive well with your re-write to have the module called "postgres-range-types"?

bendrucker commented 9 years ago

I was thinking postgres-range

langpavel commented 8 years ago

Hi, something new here? I'm interested in daterange type. What I can do?

jrf0110 commented 8 years ago

@langpavel It's been a while since I've looked at this. I think we did something like this:

var pg = require('pg');
var pgRangeParser = require('pg-range-parser');

pg.types.setTypeParser( 3912, function( val ){
  return pgRangeParser.parse( val );
});
langpavel commented 8 years ago

@jrf0110 Thanks for pointing me right direction. What is 3912? Is this constant final?

jrf0110 commented 8 years ago

I believe 3912 is the oid corresponding to date range. pg-range-parser only handles the range part of the parsing. The individual values of the range still come through as text, but you could then pass those to the relevant pg parsers.

langpavel commented 8 years ago

Thank you for explanation :-)

jfkw commented 5 years ago

What was the eventual outcome of this discussion? I would like to parse postgresql tstzrange into usable data structures like @jrf0110 did in pg-range-parser, and wondered if I should contribute here, another library related to node-pg-types, or if something else with that capability already exists.

I see 155a45551e8b4b2bbec00d0419ddd3943e910d3f: 2017-02-24 Add array parser for numrange[] type, approximately one year later, and repositories such as postgres-interval from @bendrucker being actively developed.

Is my understanding correct that the numarray parser from 155a45551e8b4b2bbec00d0419ddd3943e910d3f returns a string, and the application would still need its own parser to access the information encoded in that string?