[MDEV-33328] isnull(COLUMN_DEFAULT) from information_schema.columns Created: 2024-01-30 Updated: 2024-02-01 Resolved: 2024-01-30 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 10.6.16 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | Anders Gustavsson | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
10.6.16-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04 |
||
| Description |
|
I create a table with this definition:
and when I ask this question:
I get the ok answer:
But when I ask this question:
I get the strange result:
Shouldn't id and editor have the same value here? |
| Comments |
| Comment by Sergei Golubchik [ 2024-01-30 ] | |||||||||||||||||||||||||||||||||
|
No. For id the value of COLUMN_DEFAULT is NULL, meaning, there is no default value. For editor the value of COLUMN_DEFAULT is a string literal with the value of NULL — a four-character string, not an SQL NULL value. This is how you can distinguish between a column with DEFAULT NULL and a column with no default at all. | |||||||||||||||||||||||||||||||||
| Comment by Anders Gustavsson [ 2024-01-30 ] | |||||||||||||||||||||||||||||||||
|
Sorry, but you are wrong Sergei. The editor column is defined without a default value so it gets NULL as a default value, if it had been defined with default 'NULL' as a default value the result of the first query would have been:
Not the ' characters before and after NULL in the result there.
without a default value again, I get the same result for the first query and a correct result for the second query:
So you have an inconsistent behavior in your way of handling NULL values here. | |||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2024-01-30 ] | |||||||||||||||||||||||||||||||||
|
Consider the table
The first column has no default value. You cannot do
So it'll have NULL value in the COLUMN_DEFAULT column, meaning, "no value". You can find these columns with
The second and third columns are the same, the default value is NULL, if you do
columns c2 and c3 will get NULL. The value of the COLUMN_DEFAULT column will be a 4-character string literal NULL. You can find these columns with
The fourth column has a default value of the literal string NULL, the value of the COLUMN_DEFAULT column will be 'NULL'. You can find these columns with
| |||||||||||||||||||||||||||||||||
| Comment by Anders Gustavsson [ 2024-02-01 ] | |||||||||||||||||||||||||||||||||
|
Works better it the last column is named c4 in your table definition. In 5.5.68-MariaDB MariaDB Server (default in centos 7) you get the correct result of this query: select COLUMN_NAME, COLUMN_DEFAULT, isnull(COLUMN_DEFAULT) That is: ------------
------------
------------ in 10.6.16-MariaDB you get ------------
------------
------------ and for the question: select COLUMN_NAME, COLUMN_DEFAULT, isnull(COLUMN_DEFAULT) you get the correct result in 5.5.68: ------------
------------
------------ and the wrong result in 10.6.16-MariaDB: ------------
------------
------------ What you get after the insert into t1 (c1,c4) values ('a','b') is NULL values for column c2 and c3 (no 4-character string literal NULL) select * from t1 is one row in both 5.5.68 and 10.6.16, that is correct. And the result of select * from t1 is no rows in both 5.5.68 and 10.6.16, that is correct, and also the result of: select * from t1 is no rows both 5.5.68 and 10.6.16, that is correct. |