-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
single quoted default value in create table statements #1036
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty close; just a couple questions.
sql/plan/show_create_table.go
Outdated
@@ -255,7 +266,13 @@ func (i *showCreateTablesIter) produceCreateTableStatement(ctx *sql.Context, tab | |||
|
|||
// TODO: The columns that are rendered in defaults should be backticked | |||
if col.Default != nil { | |||
stmt = fmt.Sprintf("%s DEFAULT %s", stmt, col.Default.String()) | |||
def := col.Default.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know how the double-quotes get stored? I noticed in one of the test cases that the input statement used single quotes, but was output wrapped in double-quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think go stores string value like val = "example"
, and when this gets used with String() method of literal expressions, we use %q
for fmt.Sprintf
method for string type, which double quotes the double quotes, which makes it "\"example\""
.
https://github.com/dolthub/go-mysql-server/blob/main/sql/expression/literal.go#L68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something we should do at this level to prevent double quotes from being stored? I haven't dug through this code yet to understand it deeply, but I'm curious what you think. Do you see a good reason we're storing the double quotes?
Overall, I think this fix is okay, but just wanted to understand the rest of the code. I'm specifically wondering if there are other problems from storing the double quotes that we could fix if we looked a little deeper here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue I've worked on before that is related to this double quoted literal expression was for displaying column default value in information_schema.columns
table. Everytime the literal expression .String() method was called, it was adding a pair of double quotes. We use this method in FromDoltSchema
method as well as in information_schema.columns table iter, which is why the result in the columns table has at least two pairs of double quotes. To resolve this, Vinai added code where the columns table will go through analyzer and the column default values are resolved accordingly which gets rid of extra double quotes, but still ends up with one extra pair of double quotes that gets trimmed in trimColumnDefaultOutput
method in columns_table.go
Please enter a commit message to explain why this merge is necessary,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for digging deeper into the literal value quoting behavior and finding a cleaner solution for this. Awesome to tidy up information_schema.columns
a little more along the way, too. 😄
It would be good to go ahead and run the dolt tests against this GMS code to see if there are any dolt tests to patch up.
Added changes for requiring parentheses around default function expressions. To do this,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good. Just two questions to make sure we've got good test coverage and two really minor suggestions.
Current Dolt default literal values are stores in double quotes, but MySQL does not parse double quoted default literal value in
CREATE TABLE
statements for both sql shell and importing dumps.Fixes dolthub/dolt#3218
Added character set and collation columns for
show create view