Closed jrf0110 closed 8 years ago
Do range types return a specific oid that can be matched to a range of another oid?
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
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.
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"?
I was thinking postgres-range
Hi, something new here? I'm interested in daterange
type. What I can do?
@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 );
});
@jrf0110 Thanks for pointing me right direction. What is 3912? Is this constant final?
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.
Thank you for explanation :-)
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?
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).