Insert into partion table without logic statement

From: "Jolles, Peter M (GE Infra, Energy)" <peter(dot)jolles(at)ge(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Insert into partion table without logic statement
Date: 2009-01-05 17:26:15
Message-ID: 450587DECE7D17438DC4C9EFD12F0A430AB0A348@ALPMLVEM08.e2k.ad.ge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table that has multiple partitions (1000+) and I want a trigger
or rule to be able to write data automatically to each partition. One of
the values I am inserting is the table partition name, but I'm not sure
how to use it as a variable in a trigger. All trigger examples have a
series of IF statements, and I don't want to have 1000 IF statements
evaluated on every insert, not to mention adding new statements when I
have new partitions created.

Is something like the following possible? In the current form (below) I
get an INSERT INTO ERROR. I'm relatively new to databases, completely
new to Postgres, so I'm not sure if I'm headed in the right direction or
not. I'm running 8.3.5 if it makes a difference.

CREATE OR REPLACE FUNCTION mytable_insert_trigger()
RETURNS trigger AS
$BODY$
BEGIN
insert into NEW.PartitionNameVariable values (NEW.*);
return null;
END;
$BODY$
LANGUAGE 'plpgsql'

Thanks,
Peter

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2009-01-05 17:27:44 Re: Adding Arabic dictionary for TSearch2.. to_tsvector('arabic'...) doesn't work..
Previous Message Sam Mason 2009-01-05 17:19:06 Re: Adding Arabic dictionary for TSearch2.. to_tsvector('arabic'...) doesn't work..