Re: unable to assign value to composite column in trigger

From: Ketema Harris <ketema(at)ketema(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: unable to assign value to composite column in trigger
Date: 2008-12-18 21:26:32
Message-ID: 5969EECA-53ED-43FA-99C6-EDC2CFBF698A@ketema.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Dec 18, 2008, at 4:19 PM, Ketema Harris wrote:

> The following is a snippet from a trigger i am using:
>
> _mycompositeType.user_id = (OLD).mycompositeType.user_id;
> ...do some stuff... --notice that assigning from the trigger record
> works
>
> but later on...
>
> (new).mycompositeType.transaction_id := _transaction_id;
>
> Fails with syntax error at or near "("
>
> I have tried removing the () and it fails with "syntax error at or
> near "new""
>
> non composite column can be assigned to in the trigger just fine:
>
> new.other_columm := 5; --gives no issues
>
> How can a composite column be assigned to inside a trigger?
>
> Thanks
>
> Ketema J. Harris
> www.ketema.net
> ketema(at)ketema(dot)net
> ketemaj on iChat
>
>
>
> --
> 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

I have answered my own question. It appears that any composite column
elements in the NEW and OLD variables within a trigger can be read
from using the () accessor syntax, but not assigned to. What I had to
do was create a variable of the composite type and then assign the
whole column.

EX:

_var mycompositeType;

_var.element := 1
_var.element2 := 2

new.compositeCol := _var

It seems a little strange that the same accessor syntax can't be used
on both sides of the assignment operator, but this method solved my
problem.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2008-12-18 22:20:56 Re: SQL plan in functions
Previous Message Ketema Harris 2008-12-18 21:19:56 unable to assign value to composite column in trigger