From 5cd8681b807663f2dd197aad5da5f545150c4144 Mon Sep 17 00:00:00 2001 From: ushaio Date: Fri, 6 Feb 2026 21:59:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(postgres):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=90=AB=E5=A4=A7=E5=86=99=E5=AD=97=E6=AF=8D=E7=9A=84?= =?UTF-8?q?=E8=A1=A8=E5=90=8D=E6=9F=A5=E8=AF=A2=E6=8A=A5=E9=94=99=20relati?= =?UTF-8?q?on=20does=20not=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostgreSQL 会将未加双引号的标识符自动折叠为小写,导致如 Blog 表在查询时 变为 public.blog,触发 relation "public.blog" does not exist 错误。 在 needsQuote 中增加大写字母检测,确保含大写的标识符被双引号包裹。 同时修复 KingBase 的相同问题(共用同一逻辑分支)。 --- frontend/src/utils/sql.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/utils/sql.ts b/frontend/src/utils/sql.ts index 6a20d57..332e656 100644 --- a/frontend/src/utils/sql.ts +++ b/frontend/src/utils/sql.ts @@ -23,6 +23,8 @@ const needsQuote = (ident: string): boolean => { if (!ident) return false; // 如果包含特殊字符(非字母、数字、下划线)则需要引号 if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(ident)) return true; + // PostgreSQL 会将未加引号的标识符折叠为小写,含大写字母时必须加引号 + if (/[A-Z]/.test(ident)) return true; // 常见 SQL 保留字列表(简化版) const reserved = ['select', 'from', 'where', 'table', 'index', 'user', 'order', 'group', 'by', 'limit', 'offset', 'and', 'or', 'not', 'null', 'true', 'false', 'key', 'primary', 'foreign', 'references', 'default', 'constraint', 'create', 'drop', 'alter', 'insert', 'update', 'delete', 'set', 'values', 'into', 'join', 'left', 'right', 'inner', 'outer', 'on', 'as', 'is', 'in', 'like', 'between', 'case', 'when', 'then', 'else', 'end', 'having', 'distinct', 'all', 'any', 'exists', 'union', 'except', 'intersect']; return reserved.includes(ident.toLowerCase());