brianc / node-pg-types

Type parsing for node-postgres
267 stars 54 forks source link

Readme. What number represents what type. #149

Closed bbsimonbb closed 7 months ago

bbsimonbb commented 7 months ago

Overriding default handling to, say, parse numeric types, is a common thing to want to do, but in the call types.setTypeParser(20, function(val) { return parseInt(val, 10)}) taken from the readme, how are types identified? 20 represents what? Without this information, I'm helpless?

sehrope commented 7 months ago

The 20 is an example of an OID: https://www.postgresql.org/docs/current/datatype-oid.html

The built-in types that come with PostgreSQL have well defined "low" values. Custom types created by end users have higher values and may change across servers as the exact value depends on the order of creation.

bendrucker commented 7 months ago

There is much that should be improved with this readme:

PRs welcome and if I have some time I'll rewrite it myself. But ultimately the readme is pretty clear that these are OIDs and provides you with SQL commands to see the full set, which will tell you the corresponding number for every type in your database.