Support for Postgres 15 on delete set null/default column syntax

102 views
Skip to first unread message

Jared Mackey

unread,
Feb 2, 2023, 5:36:11 PM2/2/23
to elixir-ecto
Postgres 15 added the option to only nullify or default some columns on foreign key constraints. This is extremely useful syntax for tables that FK to tables that have compound primary keys and partitioned tables where the constrained table may find use in the other keys even if the related row is deleted. The new column syntax is `ON DELETE SET NULL (column_1, column_2, ...)` and `ON DELETE SET DEFAULT (column_1, column_2, ...)`. These only apply to on delete and not on update. Here's a link to the mailing list proposal from Postgres. 

Would it be possible for Ecto to support this new syntax?

Greg Rychlewski

unread,
Feb 4, 2023, 8:19:50 PM2/4/23
to elixir-ecto
This doesn't seem too hard to support for migrations. We won't be able to do anything for the on_delete association option though because those don't accept compound keys atm.

Greg Rychlewski

unread,
Feb 5, 2023, 8:55:42 AM2/5/23
to elixir-ecto
Update we added `ON DELETE SET NULL (column1, column2, ...)`: https://github.com/elixir-ecto/ecto_sql/pull/474

Mohamed Mohamed

unread,
Jun 20, 2025, 10:45:45 PMJun 20
to elixir-ecto
Could we continue this to add support for an `ON DELETE SET DEFAULT` option? In the above pull request it was mentioned that nilifying likely covers the same cases, but I have a use case where I want to set the foreign key to a known global entity instead of null when the referenced entity gets deleted. Happy to contribute if needed 😃

Greg Rychlewski

unread,
Jun 21, 2025, 7:43:27 AMJun 21
to elixir-ecto
I don't see why not :). A contribution would be welcome.
Reply all
Reply to author
Forward
0 new messages