Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Utsgl-0002gA-Fy for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Jul 2013 04:59:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Utsgk-0004XA-Vp for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Jul 2013 04:59:39 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Utsgk-0004X3-0x for pgsql-bugs@postgresql.org; Tue, 02 Jul 2013 04:59:38 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Utsgc-00013i-Rk for pgsql-bugs@postgresql.org; Tue, 02 Jul 2013 04:59:37 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Utsgc-00048a-Ax for pgsql-bugs@postgresql.org; Tue, 02 Jul 2013 04:59:30 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1UtsgX-0005d6-12 for pgsql-bugs@postgresql.org; Tue, 02 Jul 2013 04:59:25 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8275: Updateable View based on inheritance (partition) throws Error on INSERT Statement To: pgsql-bugs@postgresql.org From: rushabh.lathia@gmail.com Message-Id: Date: Tue, 02 Jul 2013 04:59:25 +0000 X-Pg-Spam-Score: 1.7 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8275 Logged by: Rushabh Lathia Email address: rushabh.lathia@gmail.com PostgreSQL version: 9.2.4 Operating system: All Description: View based on inheritance throws error on insert statement. Testcase: DROP TABLE tp_sales cascade; CREATE TABLE tp_sales ( salesman_id INT4, salesman_name VARCHAR, sales_region VARCHAR, sales_amount INT4 ); create table tp_sales_p_india ( check (sales_region = 'INDIA')) inherits (tp_sales); create table tp_sales_p_rest (check (sales_region != 'INDIA')) inherits (tp_sales); CREATE OR REPLACE FUNCTION tp_sales_insert_trigger() RETURNS TRIGGER AS $$ BEGIN IF NEW.sales_region = 'INDIA' THEN INSERT INTO tp_sales_p_india VALUES (NEW.*); ELSE INSERT INTO tp_sales_p_rest VALUES (NEW.*); END IF; RETURN NULL; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_tp_sales_trigger BEFORE INSERT ON tp_sales FOR EACH ROW EXECUTE PROCEDURE tp_sales_insert_trigger(); INSERT INTO tp_sales VALUES (100,'Foo','INDIA',15000); INSERT INTO tp_sales VALUES (110,'Bar','UK',24000); CREATE view view_tp_sales as SELECT * FROM tp_sales; -- run insert on view postgres=# INSERT INTO view_tp_sales VALUES (120,'XYZ','INDIA',11000); ERROR: new row for relation "tp_sales_p_rest" violates check constraint "tp_sales_p_rest_sales_region_check" DETAIL: Failing row contains (120, XYZ, INDIA, 11000). postgres=# INSERT INTO view_tp_sales VALUES (120,'ABC','HELLO',11000); ERROR: new row for relation "tp_sales_p_india" violates check constraint "tp_sales_p_india_sales_region_check" DETAIL: Failing row contains (120, ABC, HELLO, 11000). postgres=# select version(); version ----------------------------------------------------------------------------------------------------------------- PostgreSQL 9.4devel on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), 64-bit (1 row) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs