Reputation: 1570
I'm using PostgreSQL 9.3 and looking for a way to incorporate TIMESTAMPTZ
as true JavaScript date objects.
I understand that JavaScript does not offer Date
literal notation, so I was thinking
'{ "key" : new Date(datevalue) }'::JSON
would do the trick.
The problem is that I get the error: Token "new" is invalid.
Is it possible for me to update the Postgres JSON parser?
Maybe there is some other way I can get a bit more datatype consistency as I pass data between the front and back end... any thoughts?
Upvotes: 0
Views: 261
Reputation: 22893
That doesn't make any sense. JSON doesn't support atomic elements other than string /number / boolean. See the spec for details.
One of the main purposes of the format is to be (machine) language independent so having embedded Javascript Date objects (or Regex or Window or any other) makes no sense. What would it mean when you load that JSON in e.g. C++ - how would you call the methods on the embedded Date object?
A timestamp is text. Anything other than a number or a boolean is text. If that's not good enough for you then you either need to layer some more meaning on top of JSON or pick a different format.
Upvotes: 1