From 4e902bea0c6cbece653730448fb4384446a565be Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 4 Mar 2019 11:02:13 +0100 Subject: [PATCH] [#7518] [#8384] Add parser support for INSERT INTO t [[AS] alias] --- .../main/resources/org/jooq/web/grammar-3.12.txt | 2 +- jOOQ/src/main/java/org/jooq/impl/ParserImpl.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt index 8b6bc99857..06c296214e 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt +++ b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt @@ -307,7 +307,7 @@ selectStatement = select insertStatement = [ with ] - ( 'INSERT' | 'INS' ) [ 'INTO' ] ( tableName | '(' select ')' [ [ 'AS' ] identifier ] ) + ( 'INSERT' | 'INS' ) [ 'INTO' ] ( tableName | '(' select ')' ) [ [ 'AS' ] identifier ] [ '(' identifiers ')' ] ( values diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index c947d4f471..9d945df668 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -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;