brianc / node-pg-types

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

setTypeParser within json_agg #60

Closed nickell closed 5 years ago

nickell commented 7 years ago

Hi, I'm using the example provided to do this:

pg.types.setTypeParser(3912, parseDaterange)

However, when I've grouped documents using json_agg it doesn't seem to run those type parsers. This makes sense to me because I'm sure it's formatted as JSON by Postgres before the type parser ever sees it. I'm just curious if there's a recommended approach to parsing data types inside something like this?

leothelocust commented 7 years ago

I'm having the same issue/question.

Kyrluckechuck commented 6 years ago

Can attest I am having these problems too -- Any solution/workaround found?

nickell commented 6 years ago

Hey @Kyrluckechuck there is no workaround that I'm aware of relevant to this package so I decided to handle it with a couple postgres functions. My use-case is for camelizing json object keys and I've created a gist to share the functions with you here.

So now I can write my queries like this:

select camelize_keys(json_field) from table

or

select camelize_array(json_array_of_objects) from table

I think it makes sense to handle this sort of thing natively inside postgres. Hope that helps!