mardi 27 janvier 2015

Keep trailing zeros on Timestamp SELECT


This is the issue:

I am reading rows with a timestamp column from a table and I need to make sure that the database returns the timestamp with a fixed width. But I am encountering instances where the PostgreSQL database returns the timestamp without the trailing zeros.


The table I am working on contains UUID, Varchar, Smallint and Timestamp. I understand that I can use "to_char" as explained here, but what I am really looking for is a way tell PostgreSQL to always return the Timestamp in a given format, regardless of zeros.


Here is an example of the output from the Timestamp column I get, which contains a trimmed Timestamp:

"2014-09-26 17:17:45.999"

"2014-11-26 17:17:46"

"2015-03-26 17:17:46.001"

"2015-04-26 17:17:46.002"

"2015-05-26 17:17:46.003"



This will naturally cause a problem for me since the function that is reading from the database expects to get a Timestamp in a given format.


Is there a way to make the PostgreSQL always return a timestamp with a fixed width on "SELECT * FROM [table]" queries?


Below you see how the fields are created:

"created_UTC" timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'),

"last_modified_UTC" timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC')





Aucun commentaire:

Enregistrer un commentaire