[#7518] [#8384] Add parser support for INSERT INTO t [[AS] alias]

This commit is contained in:
lukaseder 2019-03-04 11:02:13 +01:00
parent eb6952405b
commit 4e902bea0c
2 changed files with 8 additions and 7 deletions

View File

@ -307,7 +307,7 @@ selectStatement = select
insertStatement =
[ with ]
( 'INSERT' | 'INS' ) [ 'INTO' ] ( tableName | '(' select ')' [ [ 'AS' ] identifier ] )
( 'INSERT' | 'INS' ) [ 'INTO' ] ( tableName | '(' select ')' ) [ [ 'AS' ] identifier ]
[ '(' identifiers ')' ]
(
values

View File

@ -1620,14 +1620,15 @@ final class ParserImpl implements Parser {
parseKeywordIf(ctx, "INTO");
Table<?> table = parseTableNameIf(ctx);
if (table == null) {
if (table == null)
table = table(parseSelect(ctx));
if (parseKeywordIf(ctx, "AS"))
table = table.as(parseIdentifier(ctx));
else if (!peekKeyword(ctx, "VALUES", "SELECT"))
table = table.as(parseIdentifierIf(ctx));
}
Name alias;
if (parseKeywordIf(ctx, "AS"))
table = table.as(parseIdentifier(ctx));
else if (!peekKeyword(ctx, "DEFAULT VALUES", "SEL", "SELECT", "SET", "VALUES")
&& (alias = parseIdentifierIf(ctx)) != null)
table = table.as(alias);
InsertSetStep<?> s1 = (with == null ? ctx.dsl.insertInto(table) : with.insertInto(table));
Field<?>[] fields = null;