skip to Main Content

I created a few MySQL tables via phpMyAdmin. Then I noticed that in table definitions some TIMESTAMP columns have a value attached:

timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)

What does it mean and what value should I use?

2

Answers


  1. This syntax is for fractional second precision, see the reference manual:

    https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.html

    MySQL 8.0 has fractional seconds support for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision

    Login or Signup to reply.
  2. The value after the type defines the fractional seconds part. To quote the documentation:

    MySQL 8.0 has fractional seconds support for TIME, DATETIME, and
    TIMESTAMP values, with up to microseconds (6 digits) precision:

    To define a column that includes a fractional seconds part, use the syntax type_name(fsp), where type_name is TIME, DATETIME, or
    TIMESTAMP, and fsp is the fractional seconds precision. For example:

    CREATE TABLE t1 (t TIME(3), dt DATETIME(6));
    

    The fsp value, if given, must be in the range 0 to 6. A value of 0
    signifies that there is no fractional part. If omitted, the default
    precision is 0. (This differs from the standard SQL default of 6, for
    compatibility with previous MySQL versions.)

    Therefore, to define a timestamp column with sub-second precision, you must specify a nonzero value.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search