Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: fix that char with null max length (#9726)

rebelicea526467b26b7
diff --git a/backend/plugin/db/pg/sync.go b/backend/plugin/db/pg/sync.go
index 83573c079a..c036b87bc2 100644
--- a/backend/plugin/db/pg/sync.go
+++ b/backend/plugin/db/pg/sync.go
@@ -500,7 +500,13 @@ func getTableColumns(txn *sql.Tx) (map[db.TableKey][]*storepb.ColumnMetadata, er
case "ARRAY":
column.Type = udtName.String
case "character", "character varying", "bit", "bit varying":
- column.Type = fmt.Sprintf("%s(%s)", column.Type, characterMaxLength.String)
+ if characterMaxLength.Valid {
+ // For character varying(n), the character maximum length is n.
+ // For character without length specifier, key character_maximum_length is null,
+ // we don't need to append the length.
+ // https://www.postgresql.org/docs/current/infoschema-columns.html.
+ column.Type = fmt.Sprintf("%s(%s)", column.Type, characterMaxLength.String)
+ }
}
column.Collation = collation.String
column.Comment = comment.String
diff --git a/backend/plugin/db/redshift/sync.go b/backend/plugin/db/redshift/sync.go
index 05c72d6405..cdfa31cc96 100644
--- a/backend/plugin/db/redshift/sync.go
+++ b/backend/plugin/db/redshift/sync.go
@@ -487,7 +487,13 @@ func getTableColumns(txn *sql.Tx) (map[db.TableKey][]*storepb.ColumnMetadata, er
case "ARRAY":
column.Type = udtName.String
case "character", "character varying", "bit", "bit varying":
- column.Type = fmt.Sprintf("%s(%s)", column.Type, characterMaxLength.String)
+ if characterMaxLength.Valid {
+ // For character varying(n), the character maximum length is n.
+ // For character without length specifier, key character_maximum_length is null,
+ // we don't need to append the length.
+ // https://www.postgresql.org/docs/current/infoschema-columns.html.
+ column.Type = fmt.Sprintf("%s(%s)", column.Type, characterMaxLength.String)
+ }
}
column.Collation = collation.String
column.Comment = comment.String