Merge pull request #3475 from Duncan-tree-zhou/pg_upsert_fix_duncan

修复PGOutputVisitor 输出PGInsertStatementParser的时候on Conflict Update语法的输出错误
This commit is contained in:
温绍锦
2019-10-05 14:08:57 +08:00
committed by GitHub
2 changed files with 21 additions and 1 deletions
@@ -483,7 +483,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
if (onConflictDoNothing) {
print0(ucase ? " DO NOTHING" : " do nothing");
} else if ((onConflictUpdateSetItems != null && onConflictUpdateSetItems.size() > 0)) {
print0(ucase ? " UPDATE SET " : " update set ");
print0(ucase ? " DO UPDATE SET " : " do update set ");
printAndAccept(onConflictUpdateSetItems, ", ");
}
}
@@ -0,0 +1,20 @@
package com.alibaba.druid.postgresql;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
import junit.framework.TestCase;
import org.junit.Assert;
public class PGUpsertTest extends TestCase {
public void testUpsert(){
String sql = "insert into \"test_dup\" values(1,'2',-100) on conflict(id) do update set \"count\" = test_dup.\"count\" + 1;";
String targetSql = "INSERT INTO \"test_dup\"\n"
+ "VALUES (1, '2', -100)\n"
+ "ON CONFLICT (id) DO UPDATE SET \"count\" = test_dup.\"count\" + 1";
PGSQLStatementParser parser=new PGSQLStatementParser(sql);
SQLStatement statement = parser.parseStatement();
Assert.assertEquals(targetSql, statement.toString());
}
}