pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rushabh.lathia@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8275: Updateable View based on inheritance (partition) throws Error on INSERT Statement
Date: Tue, 02 Jul 2013 04:59:25 +0000
Message-ID: <E1UtsgX-0005d6-12@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (5+ messages)  latest in thread

Message-ID: <E1UtsgX-0005d6-12@wrigleys.postgresql.org>
Permalink:  ../E1UtsgX-0005d6-12@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1UtsgX-0005d6-12@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: rushabh.lathia@gmail.com
  Subject: Re: BUG #8275: Updateable View based on inheritance (partition) throws Error on INSERT Statement
  In-Reply-To: <E1UtsgX-0005d6-12@wrigleys.postgresql.org>
  References: <E1UtsgX-0005d6-12@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox