brianc/node-pg-native

Timestamps are strangely formatted in result from SELECT

Closed this issue · 2 comments

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.

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.

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...