[#6485] Fixed aliasing syntax in MERGE

This commit is contained in:
lukaseder 2018-01-26 12:48:32 +01:00
parent 4a209aa4ce
commit c20dc27254
2 changed files with 9 additions and 3 deletions

View File

@ -238,8 +238,8 @@ setClause = fieldName '=' field
deleteStatement = 'DELETE' [ 'FROM' ] tableName [ 'WHERE' condition ] [ 'RETURNING' ( '*' | fields ) ]
;
mergeStatement = 'MERGE INTO' tableName
'USING' '(' select ')' [ 'AS' identifier ]
mergeStatement = 'MERGE INTO' tableName [ [ 'AS' ] identifier ]
'USING' '(' select ')' [ [ 'AS' ] identifier ]
'ON' condition break
{
'WHEN MATCHED THEN UPDATE' 'SET' setClauses

View File

@ -1198,13 +1198,19 @@ final class ParserImpl implements Parser {
private static final Merge<?> parseMerge(ParserContext ctx) {
parseKeyword(ctx, "MERGE INTO");
Table<?> target = parseTableName(ctx);
if (parseKeywordIf(ctx, "AS") || !peekKeyword(ctx, "USING"))
target = target.as(parseIdentifier(ctx));
parseKeyword(ctx, "USING");
parse(ctx, '(');
Select<?> using = parseSelect(ctx);
TableLike<?> usingTable = using;
parse(ctx, ')');
if (parseKeywordIf(ctx, "AS"))
if (parseKeywordIf(ctx, "AS") || !peekKeyword(ctx, "ON"))
usingTable = DSL.table(using).as(parseIdentifier(ctx));
parseKeyword(ctx, "ON");
Condition on = parseCondition(ctx);
boolean update = false;