Automating PostgreSql table partition using triggers

Поиск
Список
Период
Сортировка
От Amitabh Kant
Тема Automating PostgreSql table partition using triggers
Дата
Msg-id AANLkTimLnBoEeBmFJHEWc1vQZuvPPsp920JWyQK8CABn@mail.gmail.com
обсуждение исходный текст
Ответы Re: Automating PostgreSql table partition using triggers  (Viktor Bojović <viktor.bojovic@gmail.com>)
Re: Automating PostgreSql table partition using triggers  (Scott Marlowe <scott.marlowe@gmail.com>)
Список pgsql-sql
Hi<br /><br />I am trying to write a function which is being called from a trigger used for partitioning a large table.
Thepartitioning is to happen based on an integer field (testing_id). A simplified structure of what I am trying to do
iswritten below.<br /><br />Create Table tbltesting(<br /> testing_id int not null,<br /> testing_name character
varying(255));<br/><br />Create table tbltesting1(check(testing_id = 1)) inherits(tbltesting);<br />Create table
tbltesting2(check(testing_id= 2)) inherits(tbltesting);<br /><br />CREATE OR REPLACE FUNCTION
partition_insert_trigger()<br/>RETURNS TRIGGER AS $$<br />DECLARE id integer ;<br />BEGIN<br />    id :=
NEW.testing_id;<br />    <br />    INSERT INTO tbltesting'||id||' VALUES (NEW.*);   //Problem line, not sure what
syntaxto use here<br /><br />    RETURN NULL;<br />END;<br />$$<br />LANGUAGE plpgsql;<br /><br /><br />CREATE TRIGGER
partition_trigger<br/>    BEFORE INSERT ON tbltesting<br />    FOR EACH ROW EXECUTE PROCEDURE
partition_insert_trigger();<br/><br />Creating tables or child tables is not a problem and the trigger works fine if
thefunction has static definitions. What I am trying to achieve is use the new testing_id to create a table name for
usein the insert statement. If I am able to use the variable in the table name, I would not have to re-declare the
functioneach time with modified conditions for each separate testing_id.<br /><br /><br />With regards<br /><br
/>Amitabh<br/><br /> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Amitabh Kant
Дата:
Сообщение: Re: Automating PostgreSql table partition using triggers
Следующее
От: Viktor Bojović
Дата:
Сообщение: Re: Automating PostgreSql table partition using triggers