brianc / node-pg-native

Native (C/C++) bindings to PostgreSQL with sync and async options.
247 stars 44 forks source link

Timestamps are strangely formatted in result from SELECT #75

Closed edqallen closed 5 years ago

edqallen commented 5 years ago

Simple query of e.g. SELECT * FROM foo is returning rows with timestamps (TIMESTAMP WITH TIME ZONE) that are not valid in insert/update statements. For example: "Thu Mar 10 2016 16:43:01 GMT+0000 (Coordinated Universal Time)" which is not a valid timestamp format for use in a subsequent SQL statement such as an INSERT or UPDATE.

Is there an option I can give to the library to force timestamps to be returned unmolested? I can't (easily) select a named column and cast it, as I am creating a somewhat generic tool that needs to operate on a list of tables whos schemas are unknown beforehand.

charmander commented 5 years ago

You should be getting back Date objects, not strings formatted like that. To override the type parser for timestamptzs, see https://github.com/brianc/node-pg-types#useval => val.

edqallen commented 5 years ago

Sorry, you're right! It's giving back a Date object, it's the default Date to string handler that is messing things up when I do a ...Object.values(rowIn).join...