From 7b292d41cee961f400a58743234fa2c6c34d95ab Mon Sep 17 00:00:00 2001 From: leiziwei Date: Wed, 6 Mar 2024 17:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=8F=8C=E5=BC=95=E5=8F=B7?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=97=B6=E6=8A=8A=E5=88=AB=E5=90=8D=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E4=B8=BA=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/gram.y | 10 +++++++++- src/test/regress/expected/ignore_double_quotes.out | 14 ++++++++++++++ src/test/regress/sql/ignore_double_quotes.sql | 7 +++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 9c0ee8346..a7026c573 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -28622,7 +28622,15 @@ target_el: a_expr AS ColLabel | a_expr IDENT { $$ = makeNode(ResTarget); - $$->name = $2; + if (u_sess->attr.attr_sql.enable_ignore_case_in_dquotes + && (pg_yyget_extra(yyscanner))->core_yy_extra.ident_quoted) + { + $$->name = pg_strtolower(pstrdup($2)); + } + else + { + $$->name = $2; + } $$->indirection = NIL; $$->val = (Node *)$1; $$->location = @1; diff --git a/src/test/regress/expected/ignore_double_quotes.out b/src/test/regress/expected/ignore_double_quotes.out index 25bf04255..d8f567057 100644 --- a/src/test/regress/expected/ignore_double_quotes.out +++ b/src/test/regress/expected/ignore_double_quotes.out @@ -79,6 +79,13 @@ select * from "啊啊"; insert into ¥("¥","$") values(1,2); insert into ¥(¥,"$") values(4,3); insert into "啊啊"(",",",") values(1,2); +-- alias +create table t_ignore_case_in_dquotes_use_case0001(col1 int,col2 varchar(10)); +insert into t_ignore_case_in_dquotes_use_case0001 values(1,'one'),(2,'two'),(3,'three'); +select col1 as "AS_COL1",col2 "AS_COL2" from "t_ignore_case_in_dquotes_use_case0001" where "COL2"='two'; +ERROR: column "COL2" does not exist +LINE 1: ...rom "t_ignore_case_in_dquotes_use_case0001" where "COL2"='tw... + ^ -- function create function f1(b int) returns int as $$ @@ -264,6 +271,12 @@ call "P1"(); (1 row) +select col1 as "AS_COL1",col2 "AS_COL2" from "t_ignore_case_in_dquotes_use_case0001" where "COL2"='two'; + as_col1 | as_col2 +---------+--------- + 2 | two +(1 row) + select * from "TeSt"; A | a ---+--- @@ -336,6 +349,7 @@ drop index i1; drop view test_view; drop view "TeSt_view"; drop table test; +drop table t_ignore_case_in_dquotes_use_case0001; drop table "TeSt"; drop table "¥¥"; drop table "$"; diff --git a/src/test/regress/sql/ignore_double_quotes.sql b/src/test/regress/sql/ignore_double_quotes.sql index d9a4a7e09..d6b128dbb 100644 --- a/src/test/regress/sql/ignore_double_quotes.sql +++ b/src/test/regress/sql/ignore_double_quotes.sql @@ -39,6 +39,11 @@ insert into ¥("¥","$") values(1,2); insert into ¥(¥,"$") values(4,3); insert into "啊啊"(",",",") values(1,2); +-- alias +create table t_ignore_case_in_dquotes_use_case0001(col1 int,col2 varchar(10)); +insert into t_ignore_case_in_dquotes_use_case0001 values(1,'one'),(2,'two'),(3,'three'); +select col1 as "AS_COL1",col2 "AS_COL2" from "t_ignore_case_in_dquotes_use_case0001" where "COL2"='two'; + -- function create function f1(b int) returns int as $$ @@ -114,6 +119,7 @@ CREATE SEQUENCE "S1" START 801 CACHE 90;-- error call p1(); select * from test; call "P1"(); +select col1 as "AS_COL1",col2 "AS_COL2" from "t_ignore_case_in_dquotes_use_case0001" where "COL2"='two'; select * from "TeSt"; create table "SCH_ignore_quote_01"."TAB_quote"("A" int); insert into tab_quote (a) values (4); @@ -140,6 +146,7 @@ drop index i1; drop view test_view; drop view "TeSt_view"; drop table test; +drop table t_ignore_case_in_dquotes_use_case0001; drop table "TeSt"; drop table "¥¥"; drop table "$";