Skip to content

Commit b7e6ade

Browse files
committed
Use PostgreSQL trigger event phrases instead of standalone keywords
1 parent 307fe6e commit b7e6ade

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/languages/postgresql/postgresql.formatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const tabularOnelineClauses = expandPhrases([
4040
'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]',
4141
// - update:
4242
'UPDATE [ONLY]',
43-
'UPDATE OF',
4443
'WHERE CURRENT OF',
4544
// - insert:
4645
'ON CONFLICT',
@@ -63,7 +62,7 @@ const tabularOnelineClauses = expandPhrases([
6362
'TRUNCATE [TABLE] [ONLY]',
6463
// other
6564
'SET SCHEMA',
66-
'AFTER [INSERT]',
65+
'{BEFORE | AFTER | INSTEAD OF} {INSERT | UPDATE [OF] | DELETE | TRUNCATE}',
6766
'DEFERRABLE INITIALLY DEFERRED',
6867
// https://www.postgresql.org/docs/14/sql-commands.html
6968
'ABORT',
@@ -258,6 +257,7 @@ const reservedKeywordPhrases = expandPhrases([
258257
'DO {NOTHING | UPDATE}',
259258
'AS MATERIALIZED',
260259
'FOR EACH ROW',
260+
'OR {INSERT | UPDATE [OF] | DELETE | TRUNCATE}',
261261
'{ROWS | RANGE | GROUPS} BETWEEN',
262262
// comparison operator
263263
'IS [NOT] DISTINCT FROM',

test/postgresql.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,26 @@ describe('PostgreSqlFormatter', () => {
273273
)
274274
).toBe(dedent`
275275
CREATE CONSTRAINT TRIGGER example_trigger
276-
AFTER INSERT
277-
OR
278-
UPDATE OF column_a,
276+
AFTER INSERT OR UPDATE OF column_a,
279277
column_b ON example_table
280278
DEFERRABLE INITIALLY DEFERRED FOR EACH ROW
281279
EXECUTE PROCEDURE example_function ();
282280
`);
283281
});
282+
283+
it('formats multiple CREATE TRIGGER events without treating OR as a logical operator', () => {
284+
expect(
285+
format(
286+
`create trigger Example_Trigger
287+
after insert or update or delete on Example_Table
288+
for each row
289+
execute function Example_Function ();`,
290+
{ keywordCase: 'upper', identifierCase: 'lower' }
291+
)
292+
).toBe(dedent`
293+
CREATE TRIGGER example_trigger
294+
AFTER INSERT OR UPDATE OR DELETE ON example_table FOR EACH ROW
295+
EXECUTE FUNCTION example_function ();
296+
`);
297+
});
284298
});

0 commit comments

Comments
 (0)