Search Postgresql Archives

Insert into partion table without logic statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux