Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtdaugherty/c319225e0651b022683e382d49526b64 to your computer and use it in GitHub Desktop.
Save jtdaugherty/c319225e0651b022683e382d49526b64 to your computer and use it in GitHub Desktop.
psql session
cygnus=# create table parent (a text not null primary key);
CREATE TABLE
cygnus=# create table child (a text not null primary key references parent(a) on delete cascade on update cascade);
CREATE TABLE
cygnus=# insert into parent (a) values ('foobar');
INSERT 0 1
cygnus=# insert into parent (a) values ('foo__bar');
INSERT 0 1
cygnus=# insert into child (a) values ('foo');
ERROR: insert or update on table "child" violates foreign key constraint "child_a_fkey"
DETAIL: Key (a)=(foo) is not present in table "parent".
cygnus=# insert into child (a) values ('foobar');
INSERT 0 1
cygnus=# insert into child (a) values ('foo__bar');
INSERT 0 1
cygnus=# begin;
BEGIN
cygnus=# delete from parent;
DELETE 2
cygnus=# select * from child;
a
---
(0 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment