Skip to content

Commit

Permalink
Wrap the WHEN expression of a trigger between parenthesis, as require…
Browse files Browse the repository at this point in the history
…d by syntax

The drawback is that the BoolExpr appears even more ugly now, within three (!) parens... Sooner
or later I will try to find a solution, but the problem is not easy.

This fixes issue #18.
  • Loading branch information
lelit committed Apr 1, 2019
1 parent d0fcba8 commit 3cface9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pglast/printers/ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,10 @@ def create_trig_stmt(node, output):
output.newline()
with output.push_indent(2):
if node.whenClause:
output.write('WHEN ')
output.write('WHEN (')
with output.expression():
output.print_node(node.whenClause)
output.write(')')
output.newline()

output.write('EXECUTE PROCEDURE ')
Expand Down
20 changes: 10 additions & 10 deletions tests/test_printers_prettification/ddl/create_trigger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ CREATE TRIGGER trg_celery_periodic_tasks_950_after_update
AFTER UPDATE
ON celery.periodic_tasks
FOR EACH ROW
WHEN (( old.active IS DISTINCT FROM new.active
OR old.args IS DISTINCT FROM new.args
OR old.kwargs IS DISTINCT FROM new.kwargs
OR old.options IS DISTINCT FROM new.options
OR old.run_every IS DISTINCT FROM new.run_every
OR old.run_at_minutes IS DISTINCT FROM new.run_at_minutes
OR old.run_at_hours IS DISTINCT FROM new.run_at_hours
OR old.run_on_weekdays IS DISTINCT FROM new.run_on_weekdays
OR old.run_on_days IS DISTINCT FROM new.run_on_days
OR old.run_on_months IS DISTINCT FROM new.run_on_months))
WHEN ((( old.active IS DISTINCT FROM new.active
OR old.args IS DISTINCT FROM new.args
OR old.kwargs IS DISTINCT FROM new.kwargs
OR old.options IS DISTINCT FROM new.options
OR old.run_every IS DISTINCT FROM new.run_every
OR old.run_at_minutes IS DISTINCT FROM new.run_at_minutes
OR old.run_at_hours IS DISTINCT FROM new.run_at_hours
OR old.run_on_weekdays IS DISTINCT FROM new.run_on_weekdays
OR old.run_on_days IS DISTINCT FROM new.run_on_days
OR old.run_on_months IS DISTINCT FROM new.run_on_months)))
EXECUTE PROCEDURE celery.notify_periodic_tasks_changed()

CREATE TRIGGER trig1 AFTER UPDATE ON schema1.table1
Expand Down

0 comments on commit 3cface9

Please sign in to comment.