Support for ON DELETE clause of foreign keys?

Sorry if I missed this somehow, just didn’t see this in the docs so far. In postgres I can create a foreign key like this (inside table definition):
constraint dg_metadata_fk foreign key(staging_template) references template_metadata(name) on delete set null
OR
constraint dg_metadata_fk foreign key(staging_template) references template_metadata(name) on delete cascade

However this syntax appears to be illegal in CRDB. Does that mean the feature is not supported? If so, is there another way to achieve this using DDL in CRDB? Or do we need to do the job of the “ON DELETE” clause manually?

Hi @lexthang!

@Bram implemented ON DELETE and ON UPDATE actions recently and they’ll be supported in the upcoming 2.0 version! You can try it out now in the 2.0 betas, or look at the beta docs here: https://www.cockroachlabs.com/docs/dev/foreign-key.html#use-a-foreign-key-constraint-with-cascade-new-in-v2-0

The full list of supported ON DELETE/UPDATE actions are also on that page.

Thanks, david. That’s exactly what I wanted to know.

By the way, is there any guideline as to when 2.0 release will be out? We’re also leaning towards 2.0 instead of 1.1, because we need SEQUENCE support. But some folks are somewhat uneasy by the “beta” tag. If there’s a timeline it’s easier to respond :slight_smile:

The target release date is first week of April. The current betas are safe to use for testing.