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?

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.
    – exhuma
    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 -.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.