From 1d7f625ebf7057724892e3fcc82b7ad5983f45b6 Mon Sep 17 00:00:00 2001 From: liuhy Date: Sun, 26 Jul 2026 08:08:16 -0700 Subject: [PATCH] fix(postgresql,kingbase): quote foreign schema and table in REFERENCES The foreign schema and table were concatenated raw while the foreign columns below were double-quoted. PostgreSQL/KingBase fold unquoted identifiers to lowercase, so mixed-case foreign table names produced a REFERENCES clause pointing at a non-existent relation. Wrap in double-quotes, matching the column quoting in the same method. Fixes #2184 Co-Authored-By: Claude --- .../plugin/kingbase/enums/type/KingBaseIndexTypeEnum.java | 4 ++-- .../plugin/postgresql/enums/type/PostgreSQLIndexTypeEnum.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chat2db-community-server/chat2db-community-plugins/chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/enums/type/KingBaseIndexTypeEnum.java b/chat2db-community-server/chat2db-community-plugins/chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/enums/type/KingBaseIndexTypeEnum.java index df1080bc8a..4883ba1832 100644 --- a/chat2db-community-server/chat2db-community-plugins/chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/enums/type/KingBaseIndexTypeEnum.java +++ b/chat2db-community-server/chat2db-community-plugins/chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/enums/type/KingBaseIndexTypeEnum.java @@ -92,10 +92,10 @@ private String buildForeignColum(TableIndex tableIndex) { StringBuilder script = new StringBuilder(); script.append(" REFERENCES "); if (StringUtils.isNotBlank(tableIndex.getForeignSchemaName())) { - script.append(tableIndex.getForeignSchemaName()).append("."); + script.append("\"").append(tableIndex.getForeignSchemaName()).append("\"."); } if (StringUtils.isNotBlank(tableIndex.getForeignTableName())) { - script.append(tableIndex.getForeignTableName()).append(" "); + script.append("\"").append(tableIndex.getForeignTableName()).append("\" "); } if (CollectionUtils.isNotEmpty(tableIndex.getForeignColumnNamelist())) { script.append("("); diff --git a/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/enums/type/PostgreSQLIndexTypeEnum.java b/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/enums/type/PostgreSQLIndexTypeEnum.java index e4ecc099fa..3e36f0706d 100644 --- a/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/enums/type/PostgreSQLIndexTypeEnum.java +++ b/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/enums/type/PostgreSQLIndexTypeEnum.java @@ -92,10 +92,10 @@ private String buildForeignColum(TableIndex tableIndex) { StringBuilder script = new StringBuilder(); script.append(" REFERENCES "); if (StringUtils.isNotBlank(tableIndex.getForeignSchemaName())) { - script.append(tableIndex.getForeignSchemaName()).append("."); + script.append("\"").append(tableIndex.getForeignSchemaName()).append("\"."); } if (StringUtils.isNotBlank(tableIndex.getForeignTableName())) { - script.append(tableIndex.getForeignTableName()).append(" "); + script.append("\"").append(tableIndex.getForeignTableName()).append("\" "); } if (CollectionUtils.isNotEmpty(tableIndex.getForeignColumnNamelist())) { script.append("(");