Add parentheses around conflict target (#1704)

This commit is contained in:
Simon Binder 2022-02-21 18:43:48 +01:00
parent 1854f8b522
commit 518fdce2e9
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 13 additions and 0 deletions

View File

@ -1176,7 +1176,10 @@ class NodeSqlBuilder extends AstVisitor<void, void> {
_keyword(TokenType.conflict);
if (e.onColumns != null) {
symbol('(', spaceBefore: true);
_join(e.onColumns!, ',');
symbol(')', spaceAfter: true);
_where(e.where);
}

View File

@ -297,6 +297,16 @@ CREATE UNIQUE INDEX my_idx ON t1 (c1, c2, c3) WHERE c1 < c3;
'INSERT OR REPLACE INTO foo DEFAULT VALUES ON CONFLICT DO NOTHING');
});
test('upsert with conflict target', () {
testFormat('INSERT INTO foo VALUES (1, 2, 3) ON CONFLICT (a, b, c) '
'DO NOTHING;');
});
test('upsert with conflict target and where', () {
testFormat('INSERT INTO foo VALUES (1, 2, 3) '
'ON CONFLICT (a, b, c) WHERE foo = bar DO NOTHING;');
});
test('upsert - update', () {
testFormat('INSERT INTO foo VALUES (1, 2, 3) '
'ON CONFLICT DO UPDATE SET a = b, c = d WHERE d < a;');