0

I have a message table schema like this (msg_id, msg_from_id, msg_to_id, msg_text, msg_time). ...and I'm thinking about the conversion of the message timestamp.

  1. Store the user's timezone in the users table, do an AT TIME ZONE = 'SELECT tz FROM users where ...' while retrieving the messages.
  2. Retrieve the data just as is and convert on the client side

What's the better approach between the two?

1 Answer 1

1

The simple and correct solution is to set the database parameter timezone correctly for the client session:

SET timezone = 'Asia/Kolkata';

Then the database will render all timestamp with time zone correctly for that time zone. In short, PostgreSQL can do the time zone management for you.

Sign up to request clarification or add additional context in comments.

2 Comments

This would restrict the app's timezone to my country but since it's a personal project I guess it's fine. Is calling ''at time zone=...' for each row not a solution to consider?
It is possible - but you also have to know the session's time zone for that. And I think it is easier to set the parameter for that database session once and be done with it, rather than having to specify the time zone in each query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.