Skip to content

ERROR: syntax error at or near "s" (SQLSTATE 42601) #236

@iTanken

Description

@iTanken

When table or field comments contain ' single quotes, using logger.ExplainSQL may lead to syntax errors due to the single quotes being escaped using MySQL's syntax \' in the SQL statements.

SQLSTATE 42601

COMMENT ON COLUMN "users"."name" IS 'user\'s name'
ERROR: syntax error at or near "s" (SQLSTATE 42601)

postgres/migrator.go

Lines 167 to 174 in 68a877c

if field.Comment != "" {
if err := m.DB.Exec(
"COMMENT ON COLUMN ?.? IS ?",
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, gorm.Expr(m.Migrator.Dialector.Explain("$1", field.Comment)),
).Error; err != nil {
return err
}
}

postgres/migrator.go

Lines 216 to 223 in 68a877c

if field.Comment != "" {
if err := m.DB.Exec(
"COMMENT ON COLUMN ?.? IS ?",
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, gorm.Expr(m.Migrator.Dialector.Explain("$1", field.Comment)),
).Error; err != nil {
return err
}
}

postgres/migrator.go

Lines 270 to 277 in 68a877c

if field.Comment != "" && comment != description {
if err := m.DB.Exec(
"COMMENT ON COLUMN ?.? IS ?",
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, gorm.Expr(m.Migrator.Dialector.Explain("$1", field.Comment)),
).Error; err != nil {
return err
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions