zhxp@THINKPAD-E14:~/repositories/postgres/postgres$ psql
psql (12.14)
Type "help" for help.
postgres=# create table trigtest(i serial primary key);
CREATE TABLE
postgres=# create table trigtestfk(i int references trigtest(i) on delete cascade);
CREATE TABLE
postgres=# insert into trigtest default values;
INSERT 0 1
postgres=# insert into trigtest default values;
INSERT 0 1
postgres=# insert into trigtest default values;
INSERT 0 1
postgres=# select * from trigtest;
i
---
1
2
3
(3 rows)
postgres=# insert into trigtestfk values (1);
INSERT 0 1
postgres=# alter table trigtest disable trigger all;
ALTER TABLE
postgres=# delete from trigtest where i = 1;
DELETE 1
postgres=# select * from trigtest;
i
---
2
3
(2 rows)
postgres=# select * from trigtestfk;
i
---
1
(1 row)
postgres=# \q
zhxp@THINKPAD-E14:~/release/pg$ bin/pg_dump > trigtets.sql
zhxp@THINKPAD-E14:~/release/pg$ bin/createdb trigtest
zhxp@THINKPAD-E14:~/release/pg$ psql trigtest
psql (12.14)
Type "help" for help.
trigtest=# \i /home/zhxp/release/pg/trigtets.sql
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE SEQUENCE
ALTER TABLE
ALTER SEQUENCE
CREATE TABLE
ALTER TABLE
ALTER TABLE
COPY 2
COPY 1
setval
--------
4
(1 row)
ALTER TABLE
psql:/home/zhxp/release/pg/trigtets.sql:113: ERROR: insert or update on table "trigtestfk" violates foreign key constraint "trigtestfk_i_fkey"
DETAIL: Key (i)=(1) is not present in table "trigtest".
trigtest=#