Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHOW CREATE TABLE returns incorrect statement for json field default #4003

Closed
dphil opened this issue Aug 3, 2022 · 2 comments · Fixed by dolthub/go-mysql-server#1149
Closed
Labels
bug Something isn't working

Comments

@dphil
Copy link

dphil commented Aug 3, 2022

Using dolt 0.40.21 and using a db initialized with the new DOLT_DEFAULT_BIN_FORMAT=DOLT_1 flag.

In the CREATE TABLE call, a particular column is defined as follows:
metadata json default '{}'

But if I call SHOW CREATE TABLE tablename, it shows the field as:
metadata json DEFAULT '{map[]}'

If I then try to create a new table using the output of that SHOW CREATE TABLE command, I get the following error on that field:
Error 1105: incompatible type for default value
presumably because the default should be '{}', not '{map[]}'.

@fulghum fulghum added the bug Something isn't working label Aug 3, 2022
@fulghum
Copy link
Contributor

fulghum commented Aug 3, 2022

Thanks for reporting this one. I was able to reproduce this and will get started on the fix.

@fulghum
Copy link
Contributor

fulghum commented Aug 3, 2022

Tested this with Dolt, MySQL, and read through the relevant MySQL docs a bit...

On MySQL, create table t(metadata json default '{}'); returns an error, because json/blob/text/geometry columns are not allowed to have literal default values. However, you can wrap them in parens to make them an expression default value: create table t(metadata json default ('{}'));. This works on MySQL and on Dolt. I've also confirmed the output of show create table t is the same between MySQL and Dolt when using the empty json map value as an expression.

I'll update Dolt to match MySQL's behavior here and return an error when specifying a literal column default value for json/blob/text/geometry columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants