Comments (4)
@Mickael-van-der-Beek Thatβs expected; you can set its type parser.
=> SELECT typname, oid, typarray FROM pg_type WHERE typname = 'text';
typname | oid | typarray
---------+-----+----------
text | 25 | 1009
(1 row)
=> SELECT typname, oid, typarray FROM pg_type WHERE typname = 'my_enum';
typname | oid | typarray
---------+--------+----------
my_enum | 381744 | 381743
(1 row)
const OID_ARRAY_TEXT = 1009;
const OID_ARRAY_MY_ENUM = 381743;
pg.types.setTypeParser(OID_ARRAY_MY_ENUM, pg.types.getTypeParser(OID_ARRAY_TEXT));
from node-pg-types.
For any poor souls that find their way here, this will set all existing enum types to be parsed as text:
// node-postgres doesn't properly handle enum arrays out of the box,
// so we have to manually set them up here to parse as text arrays.
//
// https://github.com/brianc/node-pg-types/issues/56
const textArrayOID = (
await pool.query("SELECT typarray FROM pg_type WHERE typname = 'text'")
).rows[0].typarray;
const enumOIDs = (
await pool.query("SELECT typname, typarray FROM pg_type WHERE typtype = 'e'")
).rows;
const arrayTextParser = pg.types.getTypeParser(textArrayOID);
enumOIDs.forEach(({ typname, typarray }) => {
const parser =
{
// Parsers for specific types can be set up here, for example:
// topic_tags: value => arrayTextParser(value).map(s => s.toLowerCase()),
}[typname] || arrayTextParser;
pg.types.setTypeParser(typarray, parser);
});
Obviously, based on the number of issues pointing here, this should just be the default behavior instead of each downstream library having to re-implement enum array parsing itself. @bendrucker could this be re-opened?
from node-pg-types.
@brianc Would it be possible to know if this is considered a bug or expected behaviour?
from node-pg-types.
Querying OID info and registering parsers as you have is clever
this should just be the default behavior
Definitely not. Changing parser registration from sync into async is a big (breaking) change. Coming in hot on a 7 year old issue is not the way to make that kind of change.
from node-pg-types.
Related Issues (20)
- Parser not working for bigint values HOT 3
- Can I customize type parsing per query? HOT 3
- please throw when oid is nullish HOT 1
- Reuse postgres-bytea HOT 6
- Releasing the latest changes HOT 4
- parsing postgres box type? HOT 2
- should handle null values HOT 1
- overriding a type parser HOT 1
- Does full text search with to_tsquery work ? HOT 1
- Is the Date parsing fix in the current pg release? HOT 1
- How to import pg-types using ES6 syntax? HOT 2
- Not able to use with modules HOT 1
- +num over parseInt(num, 10) HOT 1
- Changelog with breaking changes? HOT 1
- Add support for parsing RECORD types (OIDs 2249 and 2287) HOT 3
- Can this package be used in the browser? HOT 2
- Tracking down geometry oids HOT 3
- Readme. What number represents what type. HOT 2
- types.setTypeParser(types.builtins.DATE) does not work
- Numeric values are parsed as strings but arrays of numerics are parsed as number arrays HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-pg-types.