diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 55cb30706eef22f24e4835f3ce00f933dbbef22f..fb5a3e4076ac4157104cfb5d8da4553a666aa097 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -23070,7 +23070,7 @@ select_no_parens: (Node*)list_nth($5, 0), (Node*)list_nth($5, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $6); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $6); } | with_clause select_clause opt_sort_clause select_limit for_locking_clause into_clause { @@ -23079,7 +23079,7 @@ select_no_parens: (Node*)list_nth($4, 0), (Node*)list_nth($4, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $6); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $6); } | with_clause select_clause opt_sort_clause opt_select_limit into_clause opt_for_locking_clause { @@ -23088,7 +23088,7 @@ select_no_parens: (Node*)list_nth($4, 0), (Node*)list_nth($4, 1), $1, yyscanner); - $$ = processIntoClauseInSelectStmt((SelectStmt *) $1, (IntoClause *) $5); + $$ = processIntoClauseInSelectStmt((SelectStmt *) $2, (IntoClause *) $5); } | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause { diff --git a/src/test/regress/expected/xc_dml.out b/src/test/regress/expected/xc_dml.out index 5bc733c4b44a5e415737b8db32ca0536693c8af0..a5aad51e8a7011f7e5a43ad46eefd8b138723f4b 100644 --- a/src/test/regress/expected/xc_dml.out +++ b/src/test/regress/expected/xc_dml.out @@ -1742,3 +1742,94 @@ DROP TABLE parent_replica_table; -- DROP TABLE UPDATE_XC_C; DROP TABLE UPDATE_XC_D; +-- +-- create some tables +-- +create table t1(val int, val2 int); +create table t2(val int, val2 int); +create table t3(val int, val2 int); +create table p1(a int, b int); +create table c1(a int, b int,d int, e int); +-- insert some rows in them +insert into t1 values(1,11),(2,11); +insert into t2 values(3,11),(4,11); +insert into t3 values(5,11),(6,11); +insert into p1 values(55,66),(77,88),(111,222),(123,345); +insert into c1 values(111,222,333,444),(123,345,567,789); +select * from t1 order by val; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +select * from t2 order by val; + val | val2 +-----+------ + 3 | 11 + 4 | 11 +(2 rows) + +select * from t3 order by val; + val | val2 +-----+------ + 5 | 11 + 6 | 11 +(2 rows) + +select * from p1 order by a; + a | b +-----+----- + 55 | 66 + 77 | 88 + 111 | 222 + 123 | 345 +(4 rows) + +select * from c1 order by a; + a | b | d | e +-----+-----+-----+----- + 111 | 222 | 333 | 444 + 123 | 345 | 567 | 789 +(2 rows) + +-- test a few queries with row marks +select * from t1 order by 1 for update of t1 nowait; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +select * from t1, t2, t3 order by 1 for update; + val | val2 | val | val2 | val | val2 +-----+------+-----+------+-----+------ + 1 | 11 | 3 | 11 | 5 | 11 + 1 | 11 | 3 | 11 | 6 | 11 + 1 | 11 | 4 | 11 | 5 | 11 + 1 | 11 | 4 | 11 | 6 | 11 + 2 | 11 | 3 | 11 | 5 | 11 + 2 | 11 | 3 | 11 | 6 | 11 + 2 | 11 | 4 | 11 | 5 | 11 + 2 | 11 | 4 | 11 | 6 | 11 +(8 rows) + +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1; + val | val2 +-----+------ + 1 | 11 + 2 | 11 +(2 rows) + +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; +ERROR: SELECT FOR UPDATE/SHARE cannot be applied to a WITH query +-- drop objects created +drop table c1; +drop table p1; +drop table t1; +drop table t2; +drop table t3; diff --git a/src/test/regress/sql/xc_dml.sql b/src/test/regress/sql/xc_dml.sql index 70c059a77d32aa3a4beb23d33212c657f5e42b46..f8c28f698ba89163e5bd2fadf9aa0595d299025e 100644 --- a/src/test/regress/sql/xc_dml.sql +++ b/src/test/regress/sql/xc_dml.sql @@ -350,3 +350,43 @@ DROP TABLE parent_replica_table; DROP TABLE UPDATE_XC_C; DROP TABLE UPDATE_XC_D; +-- +-- create some tables +-- +create table t1(val int, val2 int); +create table t2(val int, val2 int); +create table t3(val int, val2 int); + +create table p1(a int, b int); +create table c1(a int, b int,d int, e int); + +-- insert some rows in them +insert into t1 values(1,11),(2,11); +insert into t2 values(3,11),(4,11); +insert into t3 values(5,11),(6,11); + +insert into p1 values(55,66),(77,88),(111,222),(123,345); +insert into c1 values(111,222,333,444),(123,345,567,789); + +select * from t1 order by val; +select * from t2 order by val; +select * from t3 order by val; +select * from p1 order by a; +select * from c1 order by a; + +-- test a few queries with row marks +select * from t1 order by 1 for update of t1 nowait; +select * from t1, t2, t3 order by 1 for update; + +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; + +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1; +WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; +WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; + +-- drop objects created +drop table c1; +drop table p1; +drop table t1; +drop table t2; +drop table t3;