This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 216c7d2 Fix postgreSQL insert with schema. (#12787)
216c7d2 is described below
commit 216c7d250a8e236a1f0a158c16c1d29b6d426ba0
Author: tuichenchuxin <[email protected]>
AuthorDate: Tue Sep 28 17:11:19 2021 +0800
Fix postgreSQL insert with schema. (#12787)
---
.../impl/PostgreSQLStatementSQLVisitor.java | 2 +-
.../src/main/resources/case/dml/insert.xml | 20 ++++++++++++++++++++
.../src/main/resources/sql/supported/dml/insert.xml | 1 +
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index f43eda3..d17aa0a 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -580,7 +580,7 @@ public abstract class PostgreSQLStatementSQLVisitor extends
PostgreSQLStatementB
OwnerSegment owner = null;
TableNameSegment tableName;
if (null != qualifiedName.indirection()) {
- ColIdContext colId = ctx.colId();
+ ColIdContext colId = ctx.qualifiedName().colId();
owner = new OwnerSegment(colId.start.getStartIndex(),
colId.stop.getStopIndex(), new IdentifierValue(colId.getText()));
AttrNameContext attrName =
qualifiedName.indirection().indirectionEl().attrName();
tableName = new TableNameSegment(attrName.start.getStartIndex(),
attrName.stop.getStopIndex(), new IdentifierValue(attrName.getText()));
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
index 1685190..2f931ab 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
@@ -1923,4 +1923,24 @@
</value>
</values>
</insert>
+
+ <insert sql-case-id="insert_with_schema">
+ <table name="t_order" start-index="12" stop-index="22">
+ <owner name="db1" start-index="12" stop-index="14" />
+ </table>
+ <columns start-index="23" stop-index="23" />
+ <values>
+ <value>
+ <assignment-value>
+ <literal-expression value="1" start-index="32"
stop-index="32" />
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="2" start-index="34"
stop-index="34" />
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="3" start-index="36"
stop-index="36" />
+ </assignment-value>
+ </value>
+ </values>
+ </insert>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/insert.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/insert.xml
index 243a108..f2002c5 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/insert.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/insert.xml
@@ -82,4 +82,5 @@
<sql-case id="insert_all_with_multitable_with_conditional_when"
value="INSERT ALL WHEN order_total <= 100000 THEN INTO small_orders WHEN
order_total > 1000000 AND order_total <= 200000 THEN INTO medium_orders WHEN
order_total > 200000 THEN INTO large_orders SELECT order_id, order_total,
sales_rep_id, customer_id FROM orders" db-types="Oracle" />
<sql-case
id="insert_all_with_multitable_with_conditional_when_with_conditional_else"
value="INSERT ALL WHEN order_total <= 100000 THEN INTO small_orders WHEN
order_total > 100000 AND order_total <= 200000 THEN INTO medium_orders ELSE
INTO large_orders SELECT order_id, order_total, sales_rep_id, customer_id FROM
orders" db-types="Oracle" />
<sql-case id="insert_with_rank_column" value="INSERT INTO sales (rank)
VALUES (1)" db-types="Oracle" />
+ <sql-case id="insert_with_schema" value="INSERT INTO db1.t_order VALUES
(1,2,3)" />
</sql-cases>