Created
June 9, 2020 16:58
-
-
Save jtdaugherty/c319225e0651b022683e382d49526b64 to your computer and use it in GitHub Desktop.
psql session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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