Replacing "0000-00-00 00:00:00" to NULL in PostgreSQL

Anindhito Irmandharu :

I'm currently trying to migrate a MySQL database into a PostgreSQL database and apparently PostgreSQL does not support "0000-00-00 00:00:00" datetime format. I have found workaround for this which are to replace it into NULL instead, but i was wondering if this is a bad practice or something I shouldn't do.

An explanation would be great since I'm new to the database field. Thanks in advance.

Laurenz Albe :

The question you should ask yourself is: what is the meaning of these “zero timestamps” in your MySQL database? Obviously they don't represent real timestamps.

There are several possibilities:

  • Somebody used these weird timestamps rather then NULL to represent “is unknown”. In that case, you should use NULL.

  • The timestamps are used to represent infinity. In that case, use infinity.

  • Nobody has an idea what these timestamps should represent. In that case there is no good answer. Solve that problem, and then you will know how to represent the timestamps in PostgreSQL.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=217576&siteId=1