sandynz commented on issue #6729: URL: https://github.com/apache/shardingsphere/issues/6729#issuecomment-671023051
Reason analyze of: rewritten sql with wrong values clause "((?, ?))", it cause syntax error, it should be "(?, ?)" Comparing PostgreSQL and MySQL execution process, some screenshots:   ShardingInsertValuesToken have different startIndex and stopIndex.   ``` ShardingInsertValuesTokenGenerator.java @Override public InsertValuesToken generateSQLToken(final InsertStatementContext insertStatementContext) { Collection<InsertValuesSegment> insertValuesSegments = (insertStatementContext.getSqlStatement()).getValues(); InsertValuesToken result = new ShardingInsertValuesToken(getStartIndex(insertValuesSegments), getStopIndex(insertValuesSegments)); Iterator<Collection<DataNode>> originalDataNodesIterator = null == routeContext || routeContext.getRouteResult().getOriginalDataNodes().isEmpty() ? null : routeContext.getRouteResult().getOriginalDataNodes().iterator(); for (InsertValueContext each : insertStatementContext.getInsertValueContexts()) { List<ExpressionSegment> expressionSegments = each.getValueExpressions(); Collection<DataNode> dataNodes = null == originalDataNodesIterator ? Collections.emptyList() : originalDataNodesIterator.next(); result.getInsertValues().add(new ShardingInsertValue(expressionSegments, dataNodes)); } return result; } ShardingInsertValuesToken is initialized here, index from InsertValuesSegment ``` ``` PostgreSQLDMLVisitor.java private Collection<InsertValuesSegment> createInsertValuesSegments(final ValuesClauseContext ctx) { Collection<InsertValuesSegment> result = new LinkedList<>(); if (null != ctx.valuesClause()) { Collection<InsertValuesSegment> expressions = createInsertValuesSegments(ctx.valuesClause()); result.addAll(expressions); } Collection<ExpressionSegment> expressions = createInsertValuesSegments(ctx.exprList()); InsertValuesSegment insertValuesSegment = new InsertValuesSegment(ctx.exprList().start.getStartIndex(), ctx.exprList().stop.getStopIndex(), (List<ExpressionSegment>) expressions); result.add(insertValuesSegment); return result; } ctx.exprList().start.getStartIndex(), ctx.exprList().stop.getStopIndex(), 47,50 insert into varchar_tc (id, real_name) values (?, ?) , substring(46,52) is "(?, ?)" ``` Seems it caused by DMLStatement.g4, don't know exact reason ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
