Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > partitioned tab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 15875 of 17437
Post > Topic >>

partitioned table insert triggers

by reece@[EMAIL PROTECTED] (Reece Hart) Jun 21, 2008 at 10:29 AM

I'm trying to create a date-partitioned version of the postgres_log
table that is described here:
http://www.postgresql.org/docs/current/static/runtime-config-logging.html


In lieu of hardcoding the partition table names in the trigger, as shown
in the table partitioning docs, I wanted to dynamically compute the
table name. I tried:

        CREATE OR REPLACE FUNCTION postgres_log_insert_trigger()
        RETURNS TRIGGER AS $$
        DECLARE
            c text;
            ptable text :=3D 'postgres_log';
            ctable text :=3D ptable || '_' ||
        to_char(NEW.session_start_time, 'YYYY_MM');
        BEGIN
            c :=3D 'INSERT INTO ' || ctable || ' VALUES (NEW.*)';
            EXECUTE c;
            RETURN NULL;
        END;
        $$
        LANGUAGE plpgsql;

I get:
        ERROR:  NEW used in query that is not in a rule
        CONTEXT:  SQL statement "INSERT INTO
        measurement_postgres_log_2008_05 VALUES (NEW.*)"
        PL/pgSQL function "postgres_log_insert_trigger" line 7 at
        EXECUTE statement

I didn't really think that would work exactly for the reason given, but
I didn't know what else to try.

Now that my only idea is gone, the question for y'all is: how?

=EF=BB=BF(Okay, I actually do have one more idea: construct the insert
valu=
es
list with quote_literal. I'm hoping there's a better way.)=20

Thanks,
Reece

--=20
Reece Hart, http://harts.net/reece/,
GPG:0x25EC91A0


--=20
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 1 Posts in Topic:
partitioned table insert triggers
reece@[EMAIL PROTECTED]   2008-06-21 10:29:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 16:16:04 CST 2008.