Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izOVD-0000Lf-4Y for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2020 17:30:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1izOVB-0008MY-R3 for pgsql-general@arkaria.postgresql.org; Wed, 05 Feb 2020 17:30:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izOVB-0008MQ-E3 for pgsql-general@lists.postgresql.org; Wed, 05 Feb 2020 17:30:13 +0000 Received: from mailserver.concordia.psi.br ([189.91.194.5]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1izOV7-00013F-V5 for pgsql-general@postgresql.org; Wed, 05 Feb 2020 17:30:12 +0000 Received: from Marcio (unknown [186.226.37.77]) (Authenticated sender: marcio@zyontecnologia.com.br) by mailserver.concordia.psi.br (Postfix) with ESMTPA id C92CE10080B0 for ; Wed, 5 Feb 2020 15:30:04 -0200 (-02) From: =?iso-8859-1?Q?M=E1rcio_Ant=F4nio_Sepp?= To: Subject: Weird behavior with update cascade on partitioned tables when moving data between partitions Date: Wed, 5 Feb 2020 14:30:04 -0300 Message-ID: <00d801d5dc49$e7225d50$b56717f0$@com.br> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Content-Language: pt-br Thread-Index: AdXcSebvQfqVhNbnRui/Gyl8xGeD7g== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all, Update cascade apparently doesn't work as well on partiotioned tables = (when moving data between different partitions).=20 Please, look at example below: -- Create master partitioned table; CREATE TABLE users ( id serial NOT NULL, username text NOT NULL, password text, primary key (id) ) PARTITION BY RANGE ( id ); CREATE TABLE users_p0 partition OF users=20 FOR VALUES FROM (MINVALUE) TO (10); CREATE TABLE users_p1 partition OF users FOR VALUES FROM (10) TO (20); -- Create detail table; create table logs ( id serial not null, user_id integer not null, primary key (id), foreign key (user_id) references users (id) on update cascade=20 );=20 test=3D# insert into users (id, username, password) values (1, 'user', 'pass'); INSERT 0 1 test=3D# insert into logs (id, user_id) values (1, 1); INSERT 0 1 -- update without changing partition test=3D# update users set id =3D 8 where id =3D 1; UPDATE 1 -- Lets see the log table test=3D# select * from logs; id | user_id ----+--------- 1 | 8 (1 row) -- update changing partition; test=3D# update users set id =3D 12 where id =3D 8; ERROR: update or delete on table "users_p0" violates foreign key = constraint "logs_user_id_fkey1" on table "logs" DETAIL: Key (id)=3D(8) is still referenced from table "logs". IF create the foreign key with option "on update cascade on delete = cascade" after running this command: update users set id =3D 12 where id =3D 8; = the Record on logs table Will be deleted.=20 Is this the expectec behavior?=20 -- Att M=E1rcio A. Sepp