diff --git a/contrib/shark/expected/test_ddl_and_dml.out b/contrib/shark/expected/test_ddl_and_dml.out index 8fca83f24332fd1c488f477afb90e84d02bee51b..9a2294aa2bdc161cd3700aabee5211266476caa9 100644 --- a/contrib/shark/expected/test_ddl_and_dml.out +++ b/contrib/shark/expected/test_ddl_and_dml.out @@ -113,6 +113,67 @@ ERROR: Percent values must be between 0 and 100. --报错:WITH TIES必须和order by子句同时使用 select TOP (select 10) WITH TIES * from Products; ERROR: The WITH TIES clause is not allowed without a corresponding ORDER BY clause. +-- test for issue #IC1VD6 +select * from Products ORDER BY qtyavailable; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 10 | $1.50 | $15.00 + 10 | $1.50 | $15.00 + 10 | $1.50 | $15.00 + 25 | $2.00 | $50.00 + 25 | $2.00 | $50.00 +(5 rows) + +select TOP 1 * from Products ORDER BY qtyavailable; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 10 | $1.50 | $15.00 +(1 row) + +--- expect success +select * from Products ORDER BY qtyavailable offset 2 rows; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 10 | $1.50 | $15.00 + 25 | $2.00 | $50.00 + 25 | $2.00 | $50.00 +(3 rows) + +select * from Products ORDER BY qtyavailable fetch first 1 rows only; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 10 | $1.50 | $15.00 +(1 row) + +select * from Products ORDER BY qtyavailable offset 3 rows fetch first 1 rows only; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 25 | $2.00 | $50.00 +(1 row) + +select * from Products ORDER BY qtyavailable fetch first 1 rows only offset 3 rows; + qtyavailable | unitprice | inventoryvalue +--------------+-----------+---------------- + 25 | $2.00 | $50.00 +(1 row) + +--- expect failed +select TOP 1 * from Products ORDER BY qtyavailable offset 2 rows; +ERROR: A TOP clause cannot be used together with an OFFSET clause in D-format database +LINE 1: ...t TOP 1 * from Products ORDER BY qtyavailable offset 2 rows; + ^ +select TOP 1 * from Products ORDER BY qtyavailable fetch first 1 rows only; +ERROR: multiple LIMIT clauses not allowed +LINE 1: ...* from Products ORDER BY qtyavailable fetch first 1 rows onl... + ^ +select TOP 1 * from Products ORDER BY qtyavailable offset 3 rows fetch first 1 rows only; +ERROR: A TOP clause cannot be used together with an OFFSET clause in D-format database +LINE 1: ...OP 1 * from Products ORDER BY qtyavailable offset 3 rows fet... + ^ +select TOP 1 * from Products ORDER BY qtyavailable fetch first 1 rows only offset 3 rows; +ERROR: A TOP clause cannot be used together with an OFFSET clause in D-format database +LINE 1: ...ORDER BY qtyavailable fetch first 1 rows only offset 3 rows; + ^ DROP TABLE IF EXISTS Products; -- case 3: remove postfix operator -- 报错:移除后缀运算符 diff --git a/contrib/shark/sql/test_ddl_and_dml.sql b/contrib/shark/sql/test_ddl_and_dml.sql index 45a2a82aafcde807130c29995498ab9115d62a0a..925edc4769e5c9713d8b72abd59f71eef736ec06 100644 --- a/contrib/shark/sql/test_ddl_and_dml.sql +++ b/contrib/shark/sql/test_ddl_and_dml.sql @@ -64,6 +64,20 @@ select TOP 200 PERCENT * from Products; --报错:WITH TIES必须和order by子句同时使用 select TOP (select 10) WITH TIES * from Products; +-- test for issue #IC1VD6 +select * from Products ORDER BY qtyavailable; +select TOP 1 * from Products ORDER BY qtyavailable; +--- expect success +select * from Products ORDER BY qtyavailable offset 2 rows; +select * from Products ORDER BY qtyavailable fetch first 1 rows only; +select * from Products ORDER BY qtyavailable offset 3 rows fetch first 1 rows only; +select * from Products ORDER BY qtyavailable fetch first 1 rows only offset 3 rows; +--- expect failed +select TOP 1 * from Products ORDER BY qtyavailable offset 2 rows; +select TOP 1 * from Products ORDER BY qtyavailable fetch first 1 rows only; +select TOP 1 * from Products ORDER BY qtyavailable offset 3 rows fetch first 1 rows only; +select TOP 1 * from Products ORDER BY qtyavailable fetch first 1 rows only offset 3 rows; + DROP TABLE IF EXISTS Products; -- case 3: remove postfix operator diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 01643038acd95f060d060049504d5dcbd85da339..dab66b56ac18f7f6c44e2c224e56d2eae346329c 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -32927,6 +32927,14 @@ insertSelectOptions(SelectStmt *stmt, parser_errposition(exprLocation(limitOffset)))); } stmt->limitOffset = limitOffset; + if (DB_IS_CMPT(D_FORMAT) && stmt->limitCount) { + const char* message = "A TOP clause cannot be used together with an OFFSET clause in D-format database"; + InsertErrorMessage(message, u_sess->plsql_cxt.plpgsql_yylloc); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("A TOP clause cannot be used together with an OFFSET clause in D-format database"), + parser_errposition(exprLocation(limitOffset)))); + } } if (limitClause->limitCount) {