[MDEV-13132] Information Schema does not show whether column default is expression or literal Created: 2017-06-20 Updated: 2018-06-29 Resolved: 2017-07-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Admin statements |
| Affects Version/s: | 10.2.6 |
| Fix Version/s: | 10.2.7 |
| Type: | Bug | Priority: | Major |
| Reporter: | Will Bryant | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | default, expression | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
SHOW [FULL] COLUMNS/FIELDS and INFORMATION_SCHEMA.COLUMNS show these default expressions, but because these just look like strings, it seems to be impossible for a client program to tell if the default is an expression or a literal string. For example:
This makes it hard to dump and restore the schema properly in database utilities (eg. my Kitchen Sync). Note that the server does know (SHOW CREATE TABLE has quotes for the sts DEFAULT but not for the cts DEFAULT), but frameworks would have to parse this instead of using the SHOW statements or INFORMATION_SCHEMA views provided for giving the other table/column metadata. |
| Comments |
| Comment by Will Bryant [ 2017-06-20 ] | ||||||||||||||||||||||||||
|
I propose adding a column to INFORMATION_SCHEMA.COLUMNS to indicate if the COLUMN_DEFAULT is an expression. | ||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-06-20 ] | ||||||||||||||||||||||||||
|
I don't understand how the standard resolves this. DEFAULT clause is defined as
So, while it does not allow arbitrary expressions, it does suppose some generated values. Now, INFORMATION_SCHEMA.COLUMNS is a standard view, the COLUMN_DEFAULT is defined as
I don't understand what the standard specified value of the COLUMN_DEFAULT should be, if DO is not a <literal>. | ||||||||||||||||||||||||||
| Comment by Will Bryant [ 2017-06-20 ] | ||||||||||||||||||||||||||
|
Yeah, interesting. The reason I was suggesting an extra column was that I assumed the IS_GENERATED column was added for similar reasons, so it seemed like the most natural way to add more information without changing the existing columns. Is the IS_GENERATED column in the standard? | ||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-06-21 ] | ||||||||||||||||||||||||||
|
Yes, IS_GENERATED is the standard column. Now, I'm not completely sure yet, the standard is unclear, but other databases would quote the literal in the COLUMN_DEFAULT. That is, the result is like
So, perhaps, this is how the standard should be interpreted. | ||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-06-21 ] | ||||||||||||||||||||||||||
|
How other databases handle defalt values: SQL Server uses quotes for literals:
PostgreSQL also uses quotes for literals:
Oracle has a table ALL_TAB_COLUMNS, which is equivalent for INFORMATION_SCHEMA.COLUMNS. It also uses quotes for literals:
| ||||||||||||||||||||||||||
| Comment by Will Bryant [ 2017-06-25 ] | ||||||||||||||||||||||||||
|
OK, so we could easily add an extra flag in the Extra column returned by SHOW FULL FIELDS, so I think this maybe the quickest win. But if we want to add it to INFORMATION_SCHEMA.COLUMNS as well, which I would prefer personally, we will have to break compatibility and introduce quotes like the other databases (or add a non-standard column). | ||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-06-26 ] | ||||||||||||||||||||||||||
|
Right. It looks like we've misunderstood the standard when INFORMATION_SCHEMA.COLUMNS was originally implemented. If yes, this is certainly a bug that should be fixed. | ||||||||||||||||||||||||||
| Comment by Sébastien Vanvelthem [ 2017-08-28 ] | ||||||||||||||||||||||||||
| Comment by Toshko Andreev [ 2017-09-08 ] | ||||||||||||||||||||||||||
|
Is it possible to add an override setting that will return the same values like before 10.2? | ||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-09-08 ] | ||||||||||||||||||||||||||
|
No, but you can use SHOW FIELDS that returns the same values as before (and the same values that INFORMATION_SCHEMA.COLUMNS used to return). | ||||||||||||||||||||||||||
| Comment by Toshko Andreev [ 2017-09-08 ] | ||||||||||||||||||||||||||
|
I'm asking because we use dbForge for MySql to do all our database administration/development and currently its broken because if this and we cannot do schema comparisons between different servers. They are working on a new version that will have support for 10.2 but it may take them months, and we can't wait that long before we must update our clients. |