T
T
Tibor1282018-12-18 10:53:42
PostgreSQL
Tibor128, 2018-12-18 10:53:42

How to adjust time in select result?

The table has a column with timestamp data.
Time is stored there UTC It is
necessary to correct it to UTC + 3 as a result of the request.
I understand that this is easy to do by listing the column names in the query, like so:

SELECT id, name, timestamp + interval '3 hour' as timestamp FROM tablename

But if there are many columns, then it is not nice to list them all in order to correct one.
How to do it in a query like:
SELECT * FROM tablename

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-12-18
@melkij

The table has a column with timestamp data.
The time is stored in UTC.

Migrate to timestamp with time zone
Then set the desired set timezone to '...'; and get all processing for timestamp with time zone correct in that timezone.
It's nice to list explicitly and only those fields that you need as a result.
If in this stupid dominance of orm you write a request with your hands, then you obviously need to know what exactly and why you want to read. Therefore, select * shows a clear anti-pattern.

V
Vitaliy Orlov, 2018-12-18
@orlov0562

Try to change the time zone before the SELECT * FROM query, something like this
Well, +interval is not necessary, there is AT TIME ZONE for this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question