Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PgSQL default action on UPDATE | DELETE of foreign keys

In PostgreSQL what is the default action over a child table referencing with foreign keys a parent table, on the UPDATE / DELETE events?

The possible ones listed are the following:

NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT

I imagine it could be NO ACTION, but the official documentation does not specify it in the events paragraph of the SELECT statement specs (unfortunately, the deeplink to the paragraph is not referenceable).

like image 416
yodabar Avatar asked Apr 05 '18 15:04

yodabar


People also ask

How do I delete a foreign key in PostgreSQL?

To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student ) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint. In our example, the name of this constraint is fk_student_city_id .

Can foreign key be null Postgres?

A foreign key containing null values cannot match the values of a parent key, since a parent key by definition can have no null values. However, a null foreign key value is always valid, regardless of the value of any of its non-null parts.

Can we update foreign key in a table?

The FOREIGN KEY Constraint is a column or list of columns which points to the PRIMARY KEY of another table. you cannot simply update either child or parent table information in a Foreign Key relationship and that's the the purpose of it. If you want to update them, you have to enable, Update CASCADE on Parent table.


1 Answers

It's right there in the description of the REFERENCES clause

Quote from the manual

NO ACTION

.... This is the default action.

like image 177
a_horse_with_no_name Avatar answered Nov 15 '22 04:11

a_horse_with_no_name