sql - Insert into partitioned table return violates check constraint but shouldn't -


i've table in postgresql , want partitioned. structure below

table "dtd1"."logadminactivity" (      "username" character varying( 200 ) not null,      "action" character varying( 100 ) not null,      "pk" character varying( 5 )  not null,      "tabel" character varying( 200 )not null,      "timestamp" timestamp without time zone ); 

then i've create partition table inherit tabel "dtd1"."logadminactivity" above this:

create table "dtd1".logadminactivity_kategori (      check ('tabel'='kategori') ) inherits ("dtd1"."logadminactivity");  create table "dtd1".logadminactivity_subyek (     check ('tabel'='subyek')  ) inherits ("dtd1"."logadminactivity");  ...  create table "dtd1".logadminactivity_satuan (     check ('tabel'='satuan')  ) inherits ("dtd1"."logadminactivity");  create table "dtd1".logadminactivity_memberfilter (     check ('tabel'='memberfilter')  ) inherits ("dtd1"."logadminactivity"); 

after create indexes each partitioned table in username coloumn. create trigger function , trigger call trigger function in below. so, when insert data, coresponding tabel coloumn redirected proper partition table.

create or replace function "dtd1".logadminactivity_insert_trigger() returns trigger $$ begin     if ( new."tabel" = 'kategori' )         insert "dtd1".logadminactivity_kategori values (new.*);     elsif ( new."tabel" = 'subyek' )         insert "dtd1".logadminactivity_subyek values (new.*);     ..         else         raise exception 'tabel out of range.  fix logadminactivity_insert_trigger() function!' ;     end if;     return null; end; $$ language plpgsql;  create trigger insert_logadminactivity_trigger     before insert on "dtd1"."logadminactivity"     each row execute procedure "dtd1".logadminactivity_insert_trigger(); 

then test insert procedure such

insert "dtd1"."logadminactivity_subyek" ( "action", "pk", "tabel", "timestamp", "username")  values ( 'bla', '12312', 'subyek', '2014-01-01 02:02:03', 'asdf' ); 

but why return error this

error: new row relation "logadminactivity_subyek" violates check constraint "logadminactivity_subyek_check" detail: failing row contains (asdf, bla, subyek, 12312, 2014-01-01 02:02:03).

how can happened because i've try follow documentation in ?

http://www.postgresql.org/docs/9.3/static/ddl-partitioning.html

i think 'tabel' value query above ('subyek') not match trigger function when check check constrain pass. there part miss or there solution solve problem?

regards

check ('tabel'='subyek') 

that check constraint incorrect because 'tabel' constant.

it equivalent check (false).

you want

check ("tabel"='subyek') 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -