@@ -22,7 +22,7 @@ var MaxSqlExecWaitTimeout = 50
2222
2323type SqlColumnInfo struct {
2424 Name string `json:"name"`
25- Type string `json:"type_text,omitempty" tf:"suppress_diff, alias:type"`
25+ Type string `json:"type_text,omitempty" tf:"alias:type,computed "`
2626 Comment string `json:"comment,omitempty"`
2727 Nullable bool `json:"nullable,omitempty" tf:"default:true"`
2828}
@@ -488,10 +488,29 @@ func columnChangesCustomizeDiff(d *schema.ResourceDiff, newTable *SqlTableInfo)
488488 return nil
489489}
490490
491+ var columnTypeAliases = map [string ]string {
492+ "integer" : "int" ,
493+ "long" : "bigint" ,
494+ "real" : "float" ,
495+ "short" : "smallint" ,
496+ "byte" : "tinyint" ,
497+ "decimal" : "decimal(10,0)" ,
498+ "dec" : "decimal(10,0)" ,
499+ "numeric" : "decimal(10,0)" ,
500+ }
501+
502+ func getColumnType (columnType string ) string {
503+ caseInsensitiveColumnType := strings .ToLower (columnType )
504+ if alias , ok := columnTypeAliases [caseInsensitiveColumnType ]; ok {
505+ return alias
506+ }
507+ return caseInsensitiveColumnType
508+ }
509+
491510func assertNoColumnTypeDiff (oldCols []interface {}, newColumnInfos []SqlColumnInfo ) error {
492511 for i , oldCol := range oldCols {
493512 oldColMap := oldCol .(map [string ]interface {})
494- if oldColMap ["type" ] != newColumnInfos [i ].Type {
513+ if getColumnType ( oldColMap ["type" ].( string )) != getColumnType ( newColumnInfos [i ].Type ) {
495514 return fmt .Errorf ("changing the 'type' of an existing column is not supported" )
496515 }
497516 }
@@ -511,7 +530,7 @@ func assertNoColumnMembershipAndFieldValueUpdate(oldCols []interface{}, newColum
511530 }
512531 for name , oldColMap := range oldColsNameToMap {
513532 if newCol , exists := newColsNameToMap [name ]; exists {
514- if oldColMap ["type" ] != newCol .Type || oldColMap ["nullable" ] != newCol .Nullable || oldColMap ["comment" ] != newCol .Comment {
533+ if getColumnType ( oldColMap ["type" ].( string )) != getColumnType ( newCol .Type ) || oldColMap ["nullable" ] != newCol .Nullable || oldColMap ["comment" ] != newCol .Comment {
515534 return fmt .Errorf ("detected changes in both number of columns and existing column field values, please do not change number of columns and update column values at the same time" )
516535 }
517536 }
@@ -540,6 +559,9 @@ func ResourceSqlTable() common.Resource {
540559
541560 s ["partitions" ].ConflictsWith = []string {"cluster_keys" }
542561 s ["cluster_keys" ].ConflictsWith = []string {"partitions" }
562+ common .MustSchemaPath (s , "column" , "type" ).DiffSuppressFunc = func (k , old , new string , d * schema.ResourceData ) bool {
563+ return getColumnType (old ) == getColumnType (new )
564+ }
543565 return s
544566 })
545567 return common.Resource {
0 commit comments