From: | Ron Peterson <rpeterso(at)mtholyoke(dot)edu> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: on insert rule with default value |
Date: | 2012-02-22 13:52:39 |
Message-ID: | 20120222135239.GI29194@mtholyoke.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
2012-02-21_15:51:30-0500 Ron Peterson <rpeterso(at)mtholyoke(dot)edu>:
> My rule below does not insert the the same uuid value into the test_log
> table as is created in the test table when I insert a new value. I know
> I've worked through this before, but I'm not remembering why this is.
> What's a right way to do this?
Obviously I can use a trigger function. I'm mostly wondering if there
are any tricks to accomplishing this with rules (I like the simple
syntax). I suspect the problem here is that 'new' on insert refers to
the function used to calculate the new value, /not/ the new value that
is actually inserted into the table. There are probably reasons for
that; but it would seem nicer to refer to the actual new table value
rather than the expression used to calculate it. My 2c.
-Ron-
> create table test (
> anid
> uuid
> not null
> default encode( gen_random_bytes( 16 ), 'hex' )::uuid
> primary key,
> value
> text
> );
>
> create table test_log (
> anid
> uuid,
> value
> text,
> op
> text,
> attime
> timestamp with time zone
> );
>
> create rule test_rule_a as
> on insert to test do (
> insert into test_log ( anid, value, op, attime )
> values ( new.anid, new.value, 'insert', now() )
> );
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2012-02-22 15:32:10 | Re: on insert rule with default value |
Previous Message | Gary Stainburn | 2012-02-22 12:19:09 | Re: Another constant in foreign key problem. |