sql parser improved pg support, fix #4128

This commit is contained in:
高铁
2021-01-12 22:32:04 +08:00
parent 0d5f54baaa
commit 3197ae8db9
11 changed files with 78 additions and 0 deletions
@@ -53,6 +53,8 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
protected int buckets;
protected int shards;
private boolean ifExists = false;
public SQLAlterTableStatement(){
}
@@ -85,6 +87,14 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
this.offline = offline;
}
public boolean isIfExists() {
return ifExists;
}
public void setIfExists(boolean ifExists) {
this.ifExists = ifExists;
}
public boolean isRemovePatiting() {
return removePatiting;
}
@@ -557,6 +557,10 @@ public class PGSQLStatementParser extends SQLStatementParser {
values.add(new SQLCharExpr(lexer.stringVal()));
} else if (lexer.token() == Token.LITERAL_INT) {
values.add(new SQLIdentifierExpr(lexer.numberString()));
} else if (lexer.identifierEquals(FnvHash.Constants.JSON_SET)
|| lexer.identifierEquals(FnvHash.Constants.JSONB_SET)) {
SQLExpr json_set = this.exprParser.expr();
values.add(json_set);
} else {
values.add(new SQLIdentifierExpr(lexer.stringVal()));
}
@@ -1763,6 +1763,13 @@ public class SQLStatementParser extends SQLParser {
lexer.nextToken();
SQLAlterTableStatement stmt = new SQLAlterTableStatement(getDbType());
if (lexer.token == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
stmt.setName(this.exprParser.name());
for (;;) {
@@ -5405,6 +5405,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLAlterTableStatement x) {
print0(ucase ? "ALTER TABLE " : "alter table ");
if (x.isIfExists()) {
print0(ucase ? "IF EXISTS " : "if exists ");
}
printTableSourceExpr(x.getName());
this.indentCount++;
for (int i = 0; i < x.getItems().size(); ++i) {