Skip to content

Commit e4a4413

Browse files
Fix quote/unquote logic for default values
1 parent 7a3daed commit e4a4413

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

element/column.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,19 @@ func (c Column) pkDefinition(isPrev bool) (string, bool) {
208208
if sql.IsSqlite() {
209209
// SQLite overrides, that pingcap doesn't support
210210
if opt.Tp == ast.ColumnOptionDefaultValue {
211+
// Parsed StrValue may be quoted in single quotes, which breaks SQL expression.
212+
// We need to unquote it and, if it's a TEXT column. quote it again with double quotes.
211213
expression, err := strconv.Unquote(opt.StrValue)
212214
if err != nil {
213215
expression = opt.StrValue
214216
}
215217
if len(expression) >= 2 && expression[0] == '\'' && expression[len(expression)-1] == '\'' {
216218
// remove single quotes. strconv may not detect it
217-
expression = strconv.Quote(expression[1 : len(expression)-1])
219+
expression = expression[1 : len(expression)-1]
220+
}
221+
if c.typeDefinition(isPrev) == "TEXT" {
222+
expression = strconv.Quote(expression)
218223
}
219-
220224
strSql += " DEFAULT " + expression
221225
continue
222226
}

0 commit comments

Comments
 (0)