I am brand new to PostgreSQL coming from a few years in a company who solely using MySQL and I am a little caught off guard by the TIMESTAMP type:
CREATE TABLE example (
example_id SERIAL PRIMARY KEY,
time_utc TIMESTAMP
);
INSERT INTO example (time_utc) VALUES (NOW());
SELECT * FROM example;
example_id | time_utc
------------+----------------------------
1 | 2017-11-02 21:37:26.592814
I am aware that I can simply cast the field to its less precise form:
SELECT example_id, time_utc::timestamp(0)
and am also aware that I can declare the precision in the table definition:
time_utc TIMESTAMP(0)
But is there a way to change this to be the default precision for all TIMESTAMP
fields? And similarly, is there a way to change the behavior of NOW()
to match this format (including its lack of timezone)?
For example in MySQL:
SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2017-11-02 21:41:26 |
+---------------------+
PostgreSQL:
SELECT NOW();
now
-------------------------------
2017-11-02 21:42:48.855801+00
Honestly I just can't think of any time in the past I have wished for more precision out of MySQL's timestamps and the less precise form is objectively easier on the eyes. Is this an easy configuration change or is this just something I need to suck up and deal with in my transition to PostgreSQL?
Thanks
psql
client honors the lc_time configurationtimestamp(0)
(a server side thing), does that just truncate the precision (i.e. the timestamp is stored asHH:ii:ss.000000
) when inserting?