Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make PostgreSQL timestamps display milliseconds even if zero

Tags:

postgresql

I have a postgres DB with a "timestamp" column of the type "timestamp without time zone".

If the following timestamp ("2013-01-01 12:13:14.000") is inserted into the DB, it is displayed (using PgAdmin or psql from command line) as "2013-01-01 12:13:14".

Is there an optional switch or setting that can be set in the DB somewhere that will allow the DB to display the full extent of the precision it can handle? For example I would like for it to display "2013-01-01 12:13:14.000" even if the milliseconds are indeed zero.

Of course, this is merely for quick viewing on the fly.

Your help in this regard is highly appreciated. :)

like image 240
rameezk Avatar asked Jan 28 '14 09:01

rameezk


People also ask

Should I use timestamp or Timestamptz Postgres?

Don't use the timestamp type to store timestamps, use timestamptz (also known as timestamp with time zone) instead.

What is timestamp without timezone in PostgreSQL?

In a literal that has been determined to be timestamp without time zone , PostgreSQL will silently ignore any time zone indication. That is, the resulting value is derived from the date/time fields in the input value, and is not adjusted for time zone.


1 Answers

Doesn't look like there is any such option.

What you can do instead is use to_char:

SELECT to_char(TIMESTAMP '2013-01-01 12:13:14.001', 'YYYY-MM-DD HH:MI:SS:MS');
like image 66
Craig Ringer Avatar answered Oct 22 '22 20:10

Craig Ringer