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 1gwHet-0004co-L3 for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Feb 2019 02:30:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwHer-0005PB-Br for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Feb 2019 02:30:49 +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 1gwHer-0005Op-2H for pgsql-bugs@lists.postgresql.org; Wed, 20 Feb 2019 02:30:49 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwHen-0008Re-Jh; Wed, 20 Feb 2019 02:30:47 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x1K2Uhse032039; Wed, 20 Feb 2019 11:30:43 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 3766B63899B; Wed, 20 Feb 2019 11:30:43 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 2C3DF6382B1; Wed, 20 Feb 2019 11:30:43 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 251C840066C; Wed, 20 Feb 2019 11:30:43 +0900 (JST) Message-ID: <5C6CBBC1.1050607@lab.ntt.co.jp> Date: Wed, 20 Feb 2019 11:30:25 +0900 From: Etsuro Fujita User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Subject: Re: BUG #15642: UPDATE statements that change a partition key and FDW partitions problem. References: <15642-81cfc7b20b18f5ed@postgresql.org> In-Reply-To: <15642-81cfc7b20b18f5ed@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: maxim.boguk@gmail.com, pgsql-bugs@lists.postgresql.org Cc: PG Bug reporting form X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk (2019/02/19 23:13), PG Bug reporting form wrote: > The following bug has been logged on the website: > Update statement which changes value of partition key doesn't doesn't work > with FDW partitions. > > Test script: > \c postgres > drop database IF EXISTS test; > drop database IF EXISTS test0; > drop database IF EXISTS test1; > create database test; > create database test0; > create database test1; > \c test0 > create table t (id integer not null, constraint id_check check (id<0)); > \c test1 > create table t (id integer not null, constraint id_check check (id>=0)); > \c test > create extension postgres_fdw; > create server if not exists test0 FOREIGN DATA WRAPPER postgres_fdw OPTIONS > (dbname 'test0'); > create server if not exists test1 FOREIGN DATA WRAPPER postgres_fdw OPTIONS > (dbname 'test1'); > CREATE USER MAPPING FOR public SERVER test0 OPTIONS (user 'postgres'); > CREATE USER MAPPING FOR public SERVER test1 OPTIONS (user 'postgres'); > CREATE FOREIGN TABLE t0 (id integer not null, constraint id_check check > (id<0) ) SERVER test0 OPTIONS (table_name 't'); > CREATE FOREIGN TABLE t1 (id integer not null, constraint id_check check > (id>=0)) SERVER test1 OPTIONS (table_name 't'); > create table t (id integer not null) partition by range (id); > alter table t ATTACH PARTITION t0 for values from (MINVALUE) to (0); > alter table t ATTACH PARTITION t1 for values from (0) to (MAXVALUE); > insert into t (id) values (-1); > update t set id=2 where id=-1; > > Expected: row in t1 partition. > Reality: > test=# update t set id=2 where id=-1; > ERROR: new row for relation "t" violates check constraint "id_check" > DETAIL: Failing row contains (2). > CONTEXT: remote SQL command: UPDATE public.t SET id = 2 WHERE ((id = > (-1))) > > I don't know is this case supposed to work or not, and I can't find any > related notes in documentation. Unfortunately, this is not supported as documented in the notes section of the UPDATE reference page [1]: "Currently, rows cannot be moved from a partition that is a foreign table to some other partition, but they can be moved into a foreign table if the foreign data wrapper supports it." Best regards, Etsuro Fujita [1] https://www.postgresql.org/docs/11/sql-update.html