0

I use exclusively timestamps with time-zone in PostgreSQL, but I just noticed something slightly worrying: If a client inserts/updates a record with a naïve time-stamp, PostgreSQL falls back to a default time-zone which is either given by an environment variable, localtime or a session-setting.

This might not always be correct.

Is it possible to configure PostgreSQL in a way that it will raise an error if it sees a value without time-zone?

asked Mar 10, 2020 at 10:10
3
  • PostgreSQL usually sees a string in the SQL statement that it interprets as a timestamp. Or are you using prepared statements? Commented Mar 10, 2020 at 14:59
  • In this case the data comes from a Python client. So as far as I can tell, PG will see it as a string as you say. Commented Mar 10, 2020 at 15:33
  • Then I don't think there is a lot you can do. You could set timezone to a good value, but the client can override it if it wants. Commented Mar 10, 2020 at 15:43

1 Answer 1

0

Not sure if it is feasible in your case, but you could use functions for inserting data. Use a text parameter for the timestamp and throw an error if the string doesn't contain a + or -.

answered Mar 10, 2020 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.