@@ -27,7 +27,7 @@ func (cd *ColumnDiff) generateColumnSQL(tableSchema, tableName string, targetSch
2727 // If type is changing with USING clause and there's an existing default, drop the default first
2828 if needsUsing && hasOldDefault {
2929 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT;" ,
30- qualifiedTableName , cd .New .Name )
30+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) )
3131 statements = append (statements , sql )
3232 }
3333
@@ -38,11 +38,11 @@ func (cd *ColumnDiff) generateColumnSQL(tableSchema, tableName string, targetSch
3838 // because PostgreSQL cannot implicitly cast these types
3939 if needsUsing {
4040 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s TYPE %s USING %s::%s;" ,
41- qualifiedTableName , cd .New .Name , newType , cd .New .Name , newType )
41+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) , newType , ir . QuoteIdentifier ( cd .New .Name ) , newType )
4242 statements = append (statements , sql )
4343 } else {
4444 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s TYPE %s;" ,
45- qualifiedTableName , cd .New .Name , newType )
45+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) , newType )
4646 statements = append (statements , sql )
4747 }
4848 }
@@ -52,12 +52,12 @@ func (cd *ColumnDiff) generateColumnSQL(tableSchema, tableName string, targetSch
5252 if cd .New .IsNullable {
5353 // DROP NOT NULL
5454 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL;" ,
55- qualifiedTableName , cd .New .Name )
55+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) )
5656 statements = append (statements , sql )
5757 } else {
5858 // ADD NOT NULL - generate canonical SQL only
5959 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s SET NOT NULL;" ,
60- qualifiedTableName , cd .New .Name )
60+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) )
6161 statements = append (statements , sql )
6262 }
6363 }
@@ -69,7 +69,7 @@ func (cd *ColumnDiff) generateColumnSQL(tableSchema, tableName string, targetSch
6969 // Default was dropped above; add new default if specified
7070 if newDefault != nil && * newDefault != "" {
7171 sql := fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;" ,
72- qualifiedTableName , cd .New .Name , * newDefault )
72+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) , * newDefault )
7373 statements = append (statements , sql )
7474 }
7575 } else {
@@ -80,10 +80,10 @@ func (cd *ColumnDiff) generateColumnSQL(tableSchema, tableName string, targetSch
8080 var sql string
8181 if newDefault == nil {
8282 sql = fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT;" ,
83- qualifiedTableName , cd .New .Name )
83+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) )
8484 } else {
8585 sql = fmt .Sprintf ("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;" ,
86- qualifiedTableName , cd .New .Name , * newDefault )
86+ qualifiedTableName , ir . QuoteIdentifier ( cd .New .Name ) , * newDefault )
8787 }
8888
8989 statements = append (statements , sql )
0 commit comments