Re: Partitioning table and dynamic SQL in trigger

From: silly8888 <silly8888(at)gmail(dot)com>
To: Michal Szymanski <dyrex(at)poczta(dot)onet(dot)pl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Partitioning table and dynamic SQL in trigger
Date: 2009-11-24 23:35:56
Message-ID: 3c8f9f940911241535v4ad1e321r19795239a74dd830@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How about:

IF date_trunc('month',NEW.effective_date)=date_trunc('month',now()) THEN
.....

On Tue, Nov 24, 2009 at 7:22 AM, Michal Szymanski <dyrex(at)poczta(dot)onet(dot)pl> wrote:
> In our DB we create partition table for each month (our naming
> convetion is follow , and I would like to create trigger that insert
> data to appropriate partition table accounting.cdr_y2009m05,
> accounting.cdr_y2009m06 etc..).
>
> What is the best solution to create such trigger? I can create trigger
> function as follow:
>
> CREATE OR REPLACE FUNCTION  partitionig_test RETURNS TRIGGER AS $$
> BEGIN
>    IF NEW.effective_date>=DATE '2009-05-01' and
> NEW.effective_date<DATE '2009-06-01' THEN
>                   INTO accounting.cdr_y2009m05 VALUES (NEW.*);
>   ELSE IF ....
>   ...................................
>
> but in such solution every month I have modify trigger to handle new
> month (during import I have to remember about archive months). Second
> solution is to create dynamic SQL query, but every call of
> partitionig_test I have to build long string - accounting.cdr_* table
> has 50 columns.
> Maybe you know third solution, most elegant ?
>
> Michal Szymanski
> http://blog.szymanskich.net
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Denis Lussier 2009-11-24 23:47:16 Re: [PERFORM] Strange performance degradation
Previous Message Tom Lane 2009-11-24 22:57:36 Re: exclude table from transactions