I'm puzzled by my PostgreSQL database returning different results for a timestamp(0) without time zone field. Let's say I have a table t
create table t (
x timestamp(0) without time zone
);
insert into t select now();
Now when I run select * from t from different clients, I get different outputs.
PSQL:
2014-04-06 10:22:57JDBC:
2014-04-06 10:22:57:000
(driver postgresql-9.3-1101.jdbc4.jar run through the SQLExplorer eclipse plugin)node-pg:
Sun Apr 06 2014 10:22:57 GMT+0200 (CEST)
Of the three, only PSQL is the output I expected (and require). Why is this happening, and how can I fix it without having to explicitly cast in the query?
timestamps are stored without any format in the database. The formatting is always done by the application displaying the data. Usually you can configure the SQL client to apply a specific format totimestamp(anddate) columns. As long as you retrieve a realjava.sql.Timestampinstance from the result set (e.g. usingResultSet.getTimestamp()) this client formatting does not matter.Dataobject - I was expecting the raw string value. Read the docs, right? I'll just override the type parser. You don't by any chance know of a way to do that per connection or even per query?Dataobject is. But the output seems to be the result of callingtoString()on ajava.sql.Timestampinstance. Are you by any chance simply callingSystem.out.println()with an Object obtained from aResultSet. If yes, then everything seems OK. Just work with thejava.sql.Timestampinstance.Date. Sorry for the confusion. I'm not using Java, the JDBC is just for an Eclipse plugin I'm using. I'm on JavaScript (node.js)