mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser improved for postgresql
This commit is contained in:
@@ -17,6 +17,9 @@ package com.alibaba.druid.sql.dialect.postgresql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLTimestampExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDateExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGOrderBy;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGArrayExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGTypeCastExpr;
|
||||
@@ -88,6 +91,44 @@ public class PGExprParser extends SQLExprParser {
|
||||
|
||||
return primaryRest(castExpr);
|
||||
}
|
||||
|
||||
if (expr.getClass() == SQLIdentifierExpr.class) {
|
||||
String ident = ((SQLIdentifierExpr)expr).getName();
|
||||
|
||||
if ("TIMESTAMP".equalsIgnoreCase(ident)) {
|
||||
if (lexer.token() != Token.LITERAL_ALIAS //
|
||||
&& lexer.token() != Token.LITERAL_CHARS //
|
||||
&& lexer.token() != Token.WITH) {
|
||||
return new SQLIdentifierExpr("TIMESTAMP");
|
||||
}
|
||||
|
||||
SQLTimestampExpr timestamp = new SQLTimestampExpr();
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("TIME");
|
||||
acceptIdentifier("ZONE");
|
||||
timestamp.setWithTimeZone(true);
|
||||
}
|
||||
|
||||
String literal = lexer.stringVal();
|
||||
timestamp.setLiteral(literal);
|
||||
accept(Token.LITERAL_CHARS);
|
||||
|
||||
if (identifierEquals("AT")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("TIME");
|
||||
acceptIdentifier("ZONE");
|
||||
|
||||
String timezone = lexer.stringVal();
|
||||
timestamp.setTimeZone(timezone);
|
||||
accept(Token.LITERAL_CHARS);
|
||||
}
|
||||
|
||||
|
||||
return primaryRest(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
return super.primaryRest(expr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user