Using a null value in MySQL columns of type TIMESTAMP

I got a little confused in the documentation like TIMESTAMP in MySQL and whether a null value is valid. The manual says:

The TIMESTAMP data type has the range '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC ....

which means that “0000-00-00 00:00:00” is out of range and therefore invalid. But, as far as I see, the leadership does not report this. Also, he clearly does not say that "0000-00-00 00:00:00" actual value.

Practice shows that “0000-00-00 00:00:00” works, and management will say that:

CREATE TABLE t (ts TIMESTAMP DEFAULT 0);

valid MySQL SQL. In practice, this leads to the default setting of "0000-00-00 00:00:00".

(All similar alignments with the curious fact that "1970-01-01 00:00:00" is out of range, which, IIRC, does not apply to unix32 unix time. Perhaps MySQL uses binary zero as a magic number?)

Is it safe to set the semantics to zero TIMESTAMPs in the application? Or is it an undocumented function that might disappear?

+3
source share
1 answer

DATETIME, DATE, TIMESTAMP, TIME . , "", , , , MySQL .

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-types.html

+3

Source: https://habr.com/ru/post/1754283/


All Articles