Reputation: 474
I'm working with Postgres TIMESTAMP
data types and want to change the display format anytime a SELECT
query is called.
I currently have it working as shown below:
SELECT to_char(my_time_col, 'YYYY/MM/DD HH24:MI:SS') as time_col
FROM my_table
Is there a way to have it formatted as 2018/05/31 13:00:00
for all queries either via some predefined function, or trigger (or something that I don't know about) without having to manually format the DATETIME
fields for each individual query? In other words — I just want to type this:
SELECT my_time_col
FROM my_table
Thanks in advance.
Upvotes: 0
Views: 300
Reputation: 12412
run this sql:
SET datestyle to 'ISO, DMY';
so long as you don't store fractional seconds you should get the result you want.
this setting is temporary but can be made permanent by prefixing it with
ALTER USER
username
or
ALTER DATABASE
databasename
Upvotes: 1
Reputation: 246798
There is no such setting.
The best thing is to let the application take care of the formatting.
Upvotes: 0