From fb1a44e0099ab4cefd1baa0ffb30aeaf7e942170 Mon Sep 17 00:00:00 2001 From: yanguotao Date: Sat, 9 Nov 2024 14:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3A=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8union=20all=E5=88=9B=E5=BB=BA=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=20varchar=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=9C=A8=E8=A7=86=E5=9B=BE=E4=B8=AD=E6=9C=AA=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=95=BF=E5=BA=A6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/analyze.cpp | 4 ++++ src/test/regress/expected/create_view1.out | 22 ++++++++++++++++++++++ src/test/regress/sql/create_view1.sql | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index b583236cd..65dbb7431 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -4097,6 +4097,10 @@ static Node* transformSetOperationTree(ParseState* pstate, SelectStmt* stmt, boo /* if same type and same typmod, use typmod; else default */ if (lcoltype == rcoltype && lcoltypmod == rcoltypmod) { rescoltypmod = lcoltypmod; + } else if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && lcoltype == rcoltype && \ + !(lcoltypmod == -1 || rcoltypmod == -1)) { + /* same type, neither typmod is -1, select max */ + rescoltypmod = Max(lcoltypmod, rcoltypmod); } else { rescoltypmod = -1; } diff --git a/src/test/regress/expected/create_view1.out b/src/test/regress/expected/create_view1.out index 1f16f8d3c..101023694 100755 --- a/src/test/regress/expected/create_view1.out +++ b/src/test/regress/expected/create_view1.out @@ -114,3 +114,25 @@ select relname from pg_class where relname = 'ttv1'; reset restrict_nonsystem_relation_kind; drop view ttv1; drop table t1; +create table tt3 (c1 varchar2(10),c2 varchar2(5)); +\d tt3; + Table "public.tt3" + Column | Type | Modifiers +--------+-----------------------+----------- + c1 | character varying(10) | + c2 | character varying(5) | + +create table tt_union(col1 varchar2(15)); +insert into tt_union values('1234567890abcdr'); +create view t_v3 as select c1 as id from tt3 union all select col1 from tt_union; +\d t_v3; + View "public.t_v3" + Column | Type | Modifiers +--------+-----------------------+----------- + id | character varying(15) | + +drop table tt3 cascade; +NOTICE: drop cascades to view t_v3 +drop view t_v3 cascade; +ERROR: view "t_v3" does not exist +drop table tt_union cascade; diff --git a/src/test/regress/sql/create_view1.sql b/src/test/regress/sql/create_view1.sql index 09265e77d..0413f0ab8 100644 --- a/src/test/regress/sql/create_view1.sql +++ b/src/test/regress/sql/create_view1.sql @@ -93,3 +93,13 @@ select relname from pg_class where relname = 'ttv1'; reset restrict_nonsystem_relation_kind; drop view ttv1; drop table t1; + +create table tt3 (c1 varchar2(10),c2 varchar2(5)); +\d tt3; +create table tt_union(col1 varchar2(15)); +insert into tt_union values('1234567890abcdr'); +create view t_v3 as select c1 as id from tt3 union all select col1 from tt_union; +\d t_v3; +drop table tt3 cascade; +drop view t_v3 cascade; +drop table tt_union cascade;