diff --git a/src/bin/psql/psqlscan.l b/src/bin/psql/psqlscan.l index 752a9d449..6aafa2af8 100644 --- a/src/bin/psql/psqlscan.l +++ b/src/bin/psql/psqlscan.l @@ -92,8 +92,8 @@ typedef enum IDEN_SCROLL, IDEN_DETERMINISTIC, IDEN_PACKAGE, - IDEN_BUTT, - IDEN_SELECT + IDEN_SELECT, + IDEN_BUTT }GramIdentify; /* @@ -2277,7 +2277,7 @@ analyze_state(const char* text,PsqlScanStateData* state) if (0 == state->count_to_read) return; /*if we set delimiter to other word, don`t let Begin(xp) work*/ - if (state->is_b_format && strcmp(state->delimiter_name, ";") != 0) + if (state->is_b_format && state->delimiter_name && strcmp(state->delimiter_name, ";") != 0) return; state->count_to_read--; keyValue = keywordRead(text); @@ -2343,7 +2343,9 @@ analyze_state(const char* text,PsqlScanStateData* state) } state->gram_state[IDEN_AS] = true; state->gram_state[IDEN_IS] = true; - state->gram_state[IDEN_SELECT] = true; + if (state->is_b_format) { + state->gram_state[IDEN_SELECT] = true; + } state->include_ora_comment = true; state->count_to_read = -1; break; diff --git a/src/test/regress/data/f_pro_exp_001_1.data b/src/test/regress/data/f_pro_exp_001_1.data new file mode 100644 index 000000000..5b6b2c4f3 --- /dev/null +++ b/src/test/regress/data/f_pro_exp_001_1.data @@ -0,0 +1 @@ +1,2,3,4,5,'2020-01-01 12:13:14',1.23,nothing diff --git a/src/test/regress/input/mysql_delimiter_fix.source b/src/test/regress/input/mysql_delimiter_fix.source new file mode 100644 index 000000000..7cace6aa7 --- /dev/null +++ b/src/test/regress/input/mysql_delimiter_fix.source @@ -0,0 +1,130 @@ +--delimiter bug +create database delim_fix dbcompatibility 'B'; +\c delim_fix +create or replace procedure pro_exp_001_1 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +; +end; +/ + +create table pro_exp_001_1(a int); +create or replace procedure pro_exp_001_2 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +copy f_pro_exp_001_1 from '@abs_srcdir@/data/f_pro_exp_001_1.data' delimiter ','; +perform count(*) from f_pro_exp_001_1; +begin +drop table if exists pro_exp_001_1; +create table pro_exp_001_1(h_c_id int NOT NULL, +h_c_d_id int NOT NULL, +h_c_w_id int NOT NULL, +h_d_id int NOT NULL, +h_w_id int NOT NULL, +h_date timestamp NOT NULL, +h_amount numeric(6,2) NOT NULL, +h_data varchar(24) NOT NULL) +; +for i in 1..10 loop +insert into pro_exp_001_1 select * from f_pro_exp_001_1 where h_c_id > 2800; +end loop; +end; +drop table if exists fto_pro_exp_001_1; +create table fto_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +insert into fto_pro_exp_001_1 select * from pro_exp_001_1; +delete from pro_exp_001_1; +exception +when OTHERS then +raise 'Error Occurs.'; +end; +/ + +call pro_exp_001_2(); +select * from f_pro_exp_001_1 where h_c_id = 1; + +create database db_delimiter_a dbcompatibility 'A'; +\c db_delimiter_a; +create table pro_exp_001_1(a int); +create or replace procedure pro_exp_001_1 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +copy f_pro_exp_001_1 from '@abs_srcdir@/data/f_pro_exp_001_1.data' delimiter ','; +perform count(*) from f_pro_exp_001_1; +begin +drop table if exists pro_exp_001_1; +create table pro_exp_001_1(h_c_id int NOT NULL, +h_c_d_id int NOT NULL, +h_c_w_id int NOT NULL, +h_d_id int NOT NULL, +h_w_id int NOT NULL, +h_date timestamp NOT NULL, +h_amount numeric(6,2) NOT NULL, +h_data varchar(24) NOT NULL) +; +for i in 1..10 loop +insert into pro_exp_001_1 select * from f_pro_exp_001_1 where h_c_id > 2800; +end loop; +end; +drop table if exists fto_pro_exp_001_1; +create table fto_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +insert into fto_pro_exp_001_1 select * from pro_exp_001_1; +delete from pro_exp_001_1; +exception +when OTHERS then +raise 'Error Occurs.'; +end; +/ + +call pro_exp_001_1(); +select * from f_pro_exp_001_1 where h_c_id = 1; + +\c regression +drop database delim_fix; +drop database db_delimiter_a; diff --git a/src/test/regress/output/mysql_delimiter_fix.source b/src/test/regress/output/mysql_delimiter_fix.source new file mode 100644 index 000000000..ade2c35f2 --- /dev/null +++ b/src/test/regress/output/mysql_delimiter_fix.source @@ -0,0 +1,176 @@ +--delimiter bug +create database delim_fix dbcompatibility 'B'; +\c delim_fix +create or replace procedure pro_exp_001_1 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +; +end; +/ +ERROR: syntax error at or near ";" +LINE 15: ; + ^ +QUERY: +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +; +end +create table pro_exp_001_1(a int); +create or replace procedure pro_exp_001_2 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +copy f_pro_exp_001_1 from '@abs_srcdir@/data/f_pro_exp_001_1.data' delimiter ','; +perform count(*) from f_pro_exp_001_1; +begin +drop table if exists pro_exp_001_1; +create table pro_exp_001_1(h_c_id int NOT NULL, +h_c_d_id int NOT NULL, +h_c_w_id int NOT NULL, +h_d_id int NOT NULL, +h_w_id int NOT NULL, +h_date timestamp NOT NULL, +h_amount numeric(6,2) NOT NULL, +h_data varchar(24) NOT NULL) +; +for i in 1..10 loop +insert into pro_exp_001_1 select * from f_pro_exp_001_1 where h_c_id > 2800; +end loop; +end; +drop table if exists fto_pro_exp_001_1; +create table fto_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +insert into fto_pro_exp_001_1 select * from pro_exp_001_1; +delete from pro_exp_001_1; +exception +when OTHERS then +raise 'Error Occurs.'; +end; +/ +call pro_exp_001_2(); +NOTICE: table "f_pro_exp_001_1" does not exist, skipping +CONTEXT: SQL statement "drop table if exists f_pro_exp_001_1" +PL/pgSQL function pro_exp_001_2() line 6 at SQL statement +NOTICE: table "fto_pro_exp_001_1" does not exist, skipping +CONTEXT: SQL statement "drop table if exists fto_pro_exp_001_1" +PL/pgSQL function pro_exp_001_2() line 32 at SQL statement + pro_exp_001_2 +--------------- + +(1 row) + +select * from f_pro_exp_001_1 where h_c_id = 1; + h_c_id | h_c_d_id | h_c_w_id | h_d_id | h_w_id | h_date | h_amount | h_data +--------+----------+----------+--------+--------+--------------------------+----------+--------- + 1 | 2 | 3 | 4 | 5 | Wed Jan 01 12:13:14 2020 | 1.23 | nothing +(1 row) + +create database db_delimiter_a dbcompatibility 'A'; +\c db_delimiter_a; +create table pro_exp_001_1(a int); +create or replace procedure pro_exp_001_1 as +declare +count_num int; +f_count_num int; +begin +drop table if exists f_pro_exp_001_1; +create table f_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +copy f_pro_exp_001_1 from '@abs_srcdir@/data/f_pro_exp_001_1.data' delimiter ','; +perform count(*) from f_pro_exp_001_1; +begin +drop table if exists pro_exp_001_1; +create table pro_exp_001_1(h_c_id int NOT NULL, +h_c_d_id int NOT NULL, +h_c_w_id int NOT NULL, +h_d_id int NOT NULL, +h_w_id int NOT NULL, +h_date timestamp NOT NULL, +h_amount numeric(6,2) NOT NULL, +h_data varchar(24) NOT NULL) +; +for i in 1..10 loop +insert into pro_exp_001_1 select * from f_pro_exp_001_1 where h_c_id > 2800; +end loop; +end; +drop table if exists fto_pro_exp_001_1; +create table fto_pro_exp_001_1 (h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp, +h_amount numeric(6,2), +h_data varchar(24)); +insert into fto_pro_exp_001_1 select * from pro_exp_001_1; +delete from pro_exp_001_1; +exception +when OTHERS then +raise 'Error Occurs.'; +end; +/ +call pro_exp_001_1(); +NOTICE: table "f_pro_exp_001_1" does not exist, skipping +CONTEXT: SQL statement "drop table if exists f_pro_exp_001_1" +PL/pgSQL function pro_exp_001_1() line 6 at SQL statement +NOTICE: table "fto_pro_exp_001_1" does not exist, skipping +CONTEXT: SQL statement "drop table if exists fto_pro_exp_001_1" +PL/pgSQL function pro_exp_001_1() line 32 at SQL statement + pro_exp_001_1 +--------------- + +(1 row) + +select * from f_pro_exp_001_1 where h_c_id = 1; + h_c_id | h_c_d_id | h_c_w_id | h_d_id | h_w_id | h_date | h_amount | h_data +--------+----------+----------+--------+--------+--------------------------+----------+--------- + 1 | 2 | 3 | 4 | 5 | Wed Jan 01 12:13:14 2020 | 1.23 | nothing +(1 row) + +\c regression +drop database delim_fix; +drop database db_delimiter_a; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index f99a456b9..2c14d401f 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -995,7 +995,7 @@ test: fdw_audit test: gs_global_config_audit test: detail declare_multiple_variable test: gs_dump_encrypt substr -test: composite_datum_record mysql_function b_comments mysql_syntax mysql_delimiter +test: composite_datum_record mysql_function b_comments mysql_syntax mysql_delimiter mysql_delimiter_fix test: join_test_alias alter_ctable_compress test: ignore/ignore_type_transform ignore/ignore_not_null_constraints ignore/ignore_unique_constraints ignore/ignore_no_matched_partition ignore/ignore_invalid_input