Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.1(EOL), 10.2(EOL)
-
RHEL 6
Description
Given the following server options:
explicit_defaults_for_timestamp
|
sql_mode=ANSI,NO_ZERO_DATE
|
and the following table creation code:
create table test ( |
a int, |
ts timestamp not null |
);
|
The server throws the following error:
SQL Error (1067): Invalid default value for 'ts'
Why can't we create a table with TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default?
(Remove the part about INSERT statement, since it seems to cause some confusion)
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Description |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' This sounds as if the server is forcing DEFAULT 0 clause, while it actually does not. Case in point, when we remove NO_ZERO_DATE, create table, then run the following insert statement: {code} insert into test(a) values (1); {code} It errors out with `SQL Error (1364): Field 'ts' doesn't have a default value`, which shows that the server respect the configuration and does not provide a default value. Why can't we use TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' This sounds as if the server is forcing DEFAULT 0 clause, while it actually does not. Case in point, when we remove NO_ZERO_DATE, create table, then run the following insert statement: {code} insert into test(a) values (1); {code} It errors out with {monospace}SQL Error (1364): Field 'ts' doesn't have a default value{monospace}, which shows that the server respect the configuration and does not provide a default value. Why can't we use TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? |
Description |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' This sounds as if the server is forcing DEFAULT 0 clause, while it actually does not. Case in point, when we remove NO_ZERO_DATE, create table, then run the following insert statement: {code} insert into test(a) values (1); {code} It errors out with {monospace}SQL Error (1364): Field 'ts' doesn't have a default value{monospace}, which shows that the server respect the configuration and does not provide a default value. Why can't we use TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' This sounds as if the server is forcing {{DEFAULT 0}} clause, while it actually does not. Case in point, when we remove {{NO_ZERO_DATE}}, create table, then run the following insert statement: {code} insert into test(a) values (1); {code} It errors out with {{SQL Error (1364): Field 'ts' doesn't have a default value}}, which shows that the server respect the configuration and does not provide a default value. Why can't we use TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? |
Component/s | Temporal Types [ 11000 ] | |
Labels | upstream |
Fix Version/s | N/A [ 14700 ] | |
Resolution | Not a Bug [ 6 ] | |
Status | Open [ 1 ] | Closed [ 6 ] |
Comment |
[ Would you please reconsider this bug report (or take it as an enhancement request) for the case with strict mode (STRICT_ALL_TABLE), plus NO_ZERO_DATE and ANSI, plus explicit_default_for_timestamp?
Otherwise, there doesn't seem to be anyway to get MariaDB to run with a sane configuration where we treat the TIMESTAMP field like any other field. Basically, we want the TIMESTAMP field to reject invalid data, not to reinterpret invalid data, don't update when some other field is insert, and force user to specify the field (not null) without giving a default value. ] |
Description |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' This sounds as if the server is forcing {{DEFAULT 0}} clause, while it actually does not. Case in point, when we remove {{NO_ZERO_DATE}}, create table, then run the following insert statement: {code} insert into test(a) values (1); {code} It errors out with {{SQL Error (1364): Field 'ts' doesn't have a default value}}, which shows that the server respect the configuration and does not provide a default value. Why can't we use TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? |
Given the following server options:
{code} explicit_defaults_for_timestamp sql_mode=ANSI,NO_ZERO_DATE {code} and the following table creation code: {code:sql} create table test ( a int, ts timestamp not null ); {code} The server throws the following error: bq. SQL Error (1067): Invalid default value for 'ts' Why can't we create a table with TIMESTAMP field like a normal data type, where we force the user to specify a value, but without providing a default? (Remove the part about INSERT statement, since it seems to cause some confusion) |
Resolution | Not a Bug [ 6 ] | |
Status | Closed [ 6 ] | Stalled [ 10000 ] |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | N/A [ 14700 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 10.1.16 [ 22019 ] | |
Assignee | Alexander Barkov [ bar ] |
Labels | upstream | 10.2-ga upstream |
Labels | 10.2-ga upstream | upstream |
Affects Version/s | 10.2 [ 14601 ] | |
Affects Version/s | 10.3 [ 22126 ] |
Fix Version/s | 10.1 [ 16100 ] | |
Fix Version/s | 10.2 [ 14601 ] |
Assignee | Alexander Barkov [ bar ] | Sergei Golubchik [ serg ] |
Status | Stalled [ 10000 ] | In Review [ 10002 ] |
Fix Version/s | 10.2 [ 14601 ] |
Affects Version/s | 10.3 [ 22126 ] |
Labels | upstream | upstream upstream-fixed |
Assignee | Sergei Golubchik [ serg ] | Alexander Barkov [ bar ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Assignee | Alexander Barkov [ bar ] | Sergei Golubchik [ serg ] |
Status | Stalled [ 10000 ] | In Review [ 10002 ] |
Assignee | Sergei Golubchik [ serg ] | Alexander Barkov [ bar ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 10.1.29 [ 22636 ] | |
Fix Version/s | 10.2.10 [ 22615 ] | |
Fix Version/s | 10.3.3 [ 22644 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 77049 ] | MariaDB v4 [ 150916 ] |
It does not really force the clause, because you wouldn't see it in SHOW CREATE TABLE, but it assumes it, just like it does e.g. for INT type.
It appears that in your experiment you also had sql_mode='...STRICT_ALL_TABLES...', which would indeed make this statement produce an error. Otherwise it would produce a warning of the same kind, and insert the zero value:
Here and further we use this configuration
| @@version |
| 10.1.16-MariaDB |
| @@explicit_defaults_for_timestamp |
| 1 |
Query OK, 1 row affected, 1 warning (0.07 sec)
MariaDB [test]> show warnings;
| a | ts |
| 1 | 0000-00-00 00:00:00 |
In fact, with explicit_defaults_for_timestamp it does work exactly as a normal data type. The only difference is that there is also NO_ZERO_DATE which is by definition temporal-specific.
Lets forget about NO_ZERO_DATE for a moment and compare the "base" behavior for TIMESTAMP vs INTEGER.
With strict mode:
Both tables can be created all right:
For both tables INSERT produces an error if it doesn't specify a value for the column in question:
MariaDB [test]> insert into test2 (a) values (1);
Now, without strict mode:
For both tables, INSERT produces a warning and inserts zero:
Query OK, 1 row affected, 1 warning (0.07 sec)
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
1 row in set (0.00 sec)
MariaDB [test]> insert into test2 (a) values (1);
Query OK, 1 row affected, 1 warning (0.07 sec)
MariaDB [test]> show warnings;
+---------+------+-----------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------+
| a | b |
| 1 | 0 |
| a | ts |
| 1 | 0000-00-00 00:00:00 |