fix(query): fold unquoted postgresql table identities for grid saves

This commit is contained in:
dienaso authored and GitHub committed 2026-09-29 14:10:14 +08:00
1 parent 9540f51dce
commit 4949cce746
5 files changed
+306 -4

No files matched your search

+20 -3
View File
@@ -31,7 +31,18 @@ import { canCancelQueryExecution } from "@/lib/sql/queryExecutionState";
import { isSqlErrorPositionDebugEnabled, logSqlErrorPosition, sqlErrorHasMessagePosition, sqlErrorMessageText } from "@/lib/sql/errorPosition";
import { buildExplainSql, parseExplainResult, parseDamengExplainText, parseOracleExplainText, sqlServerExplainResult, type BuildExplainSqlResult, type ExplainPlanDatabaseType } from "@/lib/diagram/explainPlan";
import { mysqlExplainCompatibilityHint } from "@/lib/diagram/mysqlExplainCompatibility";
import { allEditableColumnsWriteable, allPrimaryKeysPresent, analyzeEditableQueryEditability, analyzeSelectStructureForDisplay, resolveMetadataColumnName, resolveSourceColumnsByOrdinal, sourceColumnsForResult, type EditableQueryInfo, type EditableQuerySource } from "@/lib/sql/sqlAnalysis";
import {
allEditableColumnsWriteable,
allPrimaryKeysPresent,
analyzeEditableQueryEditability,
analyzeSelectStructureForDisplay,
foldUnquotedPostgresMetadataIdentifier,
resolveMetadataColumnName,
resolveSourceColumnsByOrdinal,
sourceColumnsForResult,
type EditableQueryInfo,
type EditableQuerySource,
} from "@/lib/sql/sqlAnalysis";
import { buildQueryWithHiddenPrimaryKeys, hiddenResultColumnIndexes, type HiddenPrimaryKeyProjection } from "@/lib/sql/editableQueryHiddenKeys";
import { ACTIVE_TAB_STORAGE_KEY, OPEN_TABS_STORAGE_KEY, restoreOpenTabsPayload, restoreOpenTabsState, serializeOpenTabs, type OpenTabsStatePayload } from "@/lib/app/openTabsPersistence";
import {
@@ -5896,7 +5907,13 @@ export const useQueryStore = defineStore("query", () => {
// unqualified object reference. Resolve metadata through the login's
// default schema (with the driver's dbo fallback) so metadata and writes
// target the same object as the original SELECT.
const schema = source.schema || (dbType === "sqlserver" ? "" : tab.schema) || "";
// PostgreSQL-compatible engines resolve an unquoted identifier by folding
// it to lower case, so the query's original spelling is not addressable:
// quoting it (grid saves) fails with `relation ... does not exist`
// (issue #10567). Fold the SQL-text schema, not a tab-selected one — the
// object tree already reports the stored spelling.
const foldedSourceSchema = foldUnquotedPostgresMetadataIdentifier(metadataDbType, source.schema, source.schemaQuoted);
const schema = foldedSourceSchema || (dbType === "sqlserver" ? "" : tab.schema) || "";
// Oracle-family connection databases are service names, not schemas. When
// the query does not qualify a schema, let the driver resolve the current
// login user's schema instead of looking up metadata under the service name.
@@ -5911,7 +5928,7 @@ export const useQueryStore = defineStore("query", () => {
const useCurrentPostgresSchema = (dbType === "postgres" || dbType === "kwdb") && !source.schema && !tab.schema;
const resolvedSchema = (dbType === "sqlserver" && !source.schema) || (ORACLE_LIKE_METADATA_TYPES.has(metadataDbType) && !schema) || resolveAgentSearchPathSchema || useCurrentPostgresSchema ? "" : metadataSchemaForConnection(conn, metadataDatabase, schema || undefined);
const metadataSchema = normalizeUppercaseFoldedMetadataIdentifier(metadataDbType, resolvedSchema || undefined, source.schema ? source.schemaQuoted : false) || "";
const metadataTableName = normalizeUppercaseFoldedMetadataIdentifier(metadataDbType, source.tableName, source.tableNameQuoted)!;
const metadataTableName = normalizeUppercaseFoldedMetadataIdentifier(metadataDbType, foldUnquotedPostgresMetadataIdentifier(metadataDbType, source.tableName, source.tableNameQuoted)!, source.tableNameQuoted)!;
// An unqualified source resolves in the tab's current external catalog on
// Doris-family federation: the statement executed there through the
// catalog execution context, so the column lookup must carry the same