Search in sources :

Example 1 with PGUpdateStatement

use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement in project druid by alibaba.

the class PGSQLStatementParser method parseUpdateStatement.

public SQLUpdateStatement parseUpdateStatement() {
    accept(Token.UPDATE);
    PGUpdateStatement udpateStatement = new PGUpdateStatement();
    SQLSelectParser selectParser = this.exprParser.createSelectParser();
    SQLTableSource tableSource = selectParser.parseTableSource();
    udpateStatement.setTableSource(tableSource);
    parseUpdateSet(udpateStatement);
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        SQLTableSource from = selectParser.parseTableSource();
        udpateStatement.setFrom(from);
    }
    if (lexer.token() == (Token.WHERE)) {
        lexer.nextToken();
        udpateStatement.setWhere(this.exprParser.expr());
    }
    if (lexer.token() == Token.RETURNING) {
        lexer.nextToken();
        for (; ; ) {
            udpateStatement.getReturning().add(this.exprParser.expr());
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            break;
        }
    }
    return udpateStatement;
}
Also used : PGUpdateStatement(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement) SQLTableSource(com.alibaba.druid.sql.ast.statement.SQLTableSource)

Aggregations

SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 PGUpdateStatement (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement)1