mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
imporved pg parser
This commit is contained in:
@@ -446,7 +446,7 @@
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.12</version>
|
||||
<version>42.2.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -4066,7 +4066,9 @@ public class SQLExprParser extends SQLParser {
|
||||
if (token != Token.SET //
|
||||
&& token != Token.DROP
|
||||
&& token != Token.PRIMARY
|
||||
&& token != Token.RPAREN) {
|
||||
&& token != Token.RPAREN
|
||||
&& token != Token.COMMA
|
||||
) {
|
||||
column.setDataType(
|
||||
parseDataType());
|
||||
}
|
||||
|
||||
@@ -1895,6 +1895,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token == Token.COLUMN) {
|
||||
SQLAlterTableAlterColumn alterColumn = parseAlterColumn();
|
||||
stmt.addItem(alterColumn);
|
||||
|
||||
if (dbType == DbType.postgresql) {
|
||||
if (lexer.token == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (lexer.token == Token.LITERAL_ALIAS) {
|
||||
SQLAlterTableAlterColumn alterColumn = parseAlterColumn();
|
||||
stmt.addItem(alterColumn);
|
||||
@@ -2381,7 +2388,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
} else if (lexer.token == Token.COLUMN) {
|
||||
lexer.nextToken();
|
||||
SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
|
||||
this.exprParser.names(item.getColumns());
|
||||
|
||||
if (dbType == DbType.postgresql) {
|
||||
item.getColumns().add(
|
||||
this.exprParser.name());
|
||||
} else {
|
||||
this.exprParser.names(item.getColumns());
|
||||
}
|
||||
|
||||
if (lexer.token == Token.CASCADE) {
|
||||
item.setCascade(true);
|
||||
@@ -2389,6 +2402,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
stmt.addItem(item);
|
||||
|
||||
if (dbType == DbType.postgresql) {
|
||||
if (lexer.token == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
} else if (lexer.token == Token.LITERAL_ALIAS) {
|
||||
SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
|
||||
this.exprParser.names(item.getColumns());
|
||||
|
||||
@@ -5424,7 +5424,9 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
SQLAlterTableItem item = x.getItems().get(i);
|
||||
if (i != 0) {
|
||||
SQLAlterTableItem former = x.getItems().get(i - 1);
|
||||
if (this.dbType == DbType.hive && former instanceof SQLAlterTableAddPartition && item instanceof SQLAlterTableAddPartition) {
|
||||
if (this.dbType == DbType.hive
|
||||
&& former instanceof SQLAlterTableAddPartition
|
||||
&& item instanceof SQLAlterTableAddPartition) {
|
||||
// ignore comma
|
||||
} else {
|
||||
print(',');
|
||||
|
||||
@@ -68,6 +68,18 @@ public class PostgresqlResourceTest extends PGTest {
|
||||
exec_test("bvt/parser/postgresql-7.txt");
|
||||
}
|
||||
|
||||
public void test_8() throws Exception {
|
||||
exec_test("bvt/parser/postgresql-8.txt");
|
||||
}
|
||||
|
||||
public void test_9() throws Exception {
|
||||
exec_test("bvt/parser/postgresql-9.txt");
|
||||
}
|
||||
|
||||
public void test_10() throws Exception {
|
||||
exec_test("bvt/parser/postgresql-10.txt");
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
System.out.println(resource);
|
||||
InputStream is = null;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE live_measures_copy (uuid, project_uuid, component_uuid, metric_uuid, value, text_value, variation, measure_data, update_marker, created_at, updated_at) AS (SELECT uuid, project_uuid, component_uuid, CAST (metric_id AS VARCHAR (40)) AS metric_uuid, value, text_value, variation, measure_data, update_marker, created_at, updated_at FROM live_measures)
|
||||
---------------------------
|
||||
CREATE TABLE live_measures_copy (
|
||||
uuid,
|
||||
project_uuid,
|
||||
component_uuid,
|
||||
metric_uuid,
|
||||
value,
|
||||
text_value,
|
||||
variation,
|
||||
measure_data,
|
||||
update_marker,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
AS
|
||||
SELECT uuid, project_uuid, component_uuid, CAST(metric_id AS VARCHAR(40)) AS metric_uuid, value
|
||||
, text_value, variation, measure_data, update_marker, created_at
|
||||
, updated_at
|
||||
FROM live_measures
|
||||
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE issue_changes_copy (
|
||||
uuid, kee,
|
||||
issue_key,
|
||||
user_login,
|
||||
change_type,
|
||||
change_data,
|
||||
created_at,
|
||||
updated_at,
|
||||
issue_change_creation_date
|
||||
)
|
||||
AS (
|
||||
SELECT CAST (id AS VARCHAR (40)) AS uuid, kee, issue_key, user_login, change_type, change_data, created_at, updated_at, issue_change_creation_date FROM issue_changes)
|
||||
---------------------------
|
||||
CREATE TABLE issue_changes_copy (
|
||||
uuid,
|
||||
kee,
|
||||
issue_key,
|
||||
user_login,
|
||||
change_type,
|
||||
change_data,
|
||||
created_at,
|
||||
updated_at,
|
||||
issue_change_creation_date
|
||||
)
|
||||
AS
|
||||
SELECT CAST(id AS VARCHAR(40)) AS uuid, kee, issue_key, user_login, change_type
|
||||
, change_data, created_at, updated_at, issue_change_creation_date
|
||||
FROM issue_changes
|
||||
Reference in New Issue
Block a user