diff --git a/contrib/dolphin/expected/keyword_ignore_test/ignore_type_transform.out b/contrib/dolphin/expected/keyword_ignore_test/ignore_type_transform.out index 63ac0e8caaa10837c92d99e67cc9fdc76c21ac30..fa5751c3b0ae7ba08f64ef0436c5a9f8f7ae087b 100644 --- a/contrib/dolphin/expected/keyword_ignore_test/ignore_type_transform.out +++ b/contrib/dolphin/expected/keyword_ignore_test/ignore_type_transform.out @@ -789,8 +789,36 @@ select * from t_nvarchar2; 123456789123456789 (3 rows) +-- test typecast with foreign key +drop table if exists t1; +NOTICE: table "t1" does not exist, skipping +create table t1( + column1 int , + column2 char(10) primary Key, + column3 int, + unique(column1) +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "t1_column1_key" for table "t1" +insert into t1 values(1,'df',22.22); +insert into t1 values(2,'df1',22.22); +insert into t1 values(3,'df2',22.22); +drop table if exists t2; +NOTICE: table "t2" does not exist, skipping +create table t2( + column1 int unique, + column2 char(10) primary Key +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t2_pkey" for table "t2" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "t2_column1_key" for table "t2" +insert into t2 values(1,'df'); +insert into t2 values(2,'dfd'); +insert into t2 values(3,'sdf'); +alter table t2 add foreign Key (column1) references t1(column2); +ERROR: insert or update on table "t2" violates foreign key constraint "t2_column1_fkey" +DETAIL: Key (column1)=(1) is not present in table "t1". drop schema sql_ignore_type_transform_test cascade; -NOTICE: drop cascades to 14 other objects +NOTICE: drop cascades to 16 other objects DETAIL: drop cascades to table t drop cascades to table t_tinyint drop cascades to table t_smallint @@ -805,4 +833,6 @@ drop cascades to table t_character drop cascades to table t_varchar2 drop cascades to table t_nvarchar2 drop cascades to table t_text +drop cascades to table t1 +drop cascades to table t2 reset current_schema; diff --git a/contrib/dolphin/plugin_parser/gram.y b/contrib/dolphin/plugin_parser/gram.y index 30ba6a7fa8190c8c8b98dd9772a9f546a7ebdfcb..2b26c4c9534eeb49ea41e4e49f024f3360dc2afe 100644 --- a/contrib/dolphin/plugin_parser/gram.y +++ b/contrib/dolphin/plugin_parser/gram.y @@ -45945,6 +45945,9 @@ static inline void ChangeBpcharCastType(TypeName* typname) * so I try to use location to distinguish the '(1)' is added by user or gram.y. since the location of * '(1)' added by gram.y is always -1. */ + if (typname->typmods == NIL) { + return; + } A_Const* typmods = (A_Const*)lfirst(list_head(typname->typmods)); if (typmods->val.val.ival == 1 && typmods->location == -1) { list_free_deep(typname->typmods); diff --git a/contrib/dolphin/sql/keyword_ignore_test/ignore_type_transform.sql b/contrib/dolphin/sql/keyword_ignore_test/ignore_type_transform.sql index 468988ae0b8840739eadd2b07db52f1ac91b4caa..9a4fa6c8afd4af2eaac48544626b2817f596539a 100644 --- a/contrib/dolphin/sql/keyword_ignore_test/ignore_type_transform.sql +++ b/contrib/dolphin/sql/keyword_ignore_test/ignore_type_transform.sql @@ -344,5 +344,28 @@ insert into t_text values(123456789123456789); insert ignore into t_nvarchar2 select cont from t_text; select * from t_nvarchar2; +-- test typecast with foreign key +drop table if exists t1; +create table t1( + column1 int , + column2 char(10) primary Key, + column3 int, + unique(column1) +); +insert into t1 values(1,'df',22.22); +insert into t1 values(2,'df1',22.22); +insert into t1 values(3,'df2',22.22); + +drop table if exists t2; +create table t2( + column1 int unique, + column2 char(10) primary Key +); +insert into t2 values(1,'df'); +insert into t2 values(2,'dfd'); +insert into t2 values(3,'sdf'); + +alter table t2 add foreign Key (column1) references t1(column2); + drop schema sql_ignore_type_transform_test cascade; reset current_schema;