ban-truncate-cascade
#
problemUsing TRUNCATE
's CASCADE
option will truncate any tables that are also foreign-keyed to the specified tables.
So if you had tables with foreign-keys like:
and ran:
You'd end up with a
, b
, & c
all being truncated!
#
runnable exampleSetup:
Then you run:
Which outputs:
And now tables a
, b
, & c
are empty!
#
solutionDon't use the CASCADE
option, instead manually specify the tables you want.
So if you just wanted tables a
and b
from the example above:
#
links- https://www.postgresql.org/docs/current/sql-truncate.html
CASCADE
's recursive nature caused Linear's 2024-01-24 incident.