Re: Verify a record has a column in a plpgsql trigger

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Verify a record has a column in a plpgsql trigger
Date: 2010-02-05 00:36:30
Message-ID: m3fx5gmsc1.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Ginsburg <mginsburg(at)collaborativefusion(dot)com> wrote:

> [...]
> Thanks for the help! I'll look into the exceptions to see
> how expensive they are. On a related note, I was just told
> by our sysadmins that pg 8.4 might not be installed by the
> time this needs to be rolled out, leaving me in a bind since
> I have been using "EXECUTE ... USING" queries. A sample of
> my trigger is below:

> FOR colRow IN SELECT attname FROM pg_catalog.pg_attribute
> WHERE attnum
>> 0 AND attrelid = TG_RELID LOOP
> EXECUTE 'SELECT ($1).' || colRow.attname || '::text' INTO n USING NEW;
> EXECUTE 'SELECT ($1).' || colRow.attname || '::text' INTO o USING OLD;
> IF n <> o THEN
> q := 'INSERT INTO change_log (...) VALUES (...);
> EXECUTE q;
> END IF;
> END LOOP;

> Any insight on a way I can grab NEW.(colRow.attname) without EXECUTE USING?

Wouldn't it be *much* easier to just have /two/ trigger
functions? Your "editor" columns probably don't pop up and
disappear randomly.

Tim

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Newton 2010-02-05 02:49:36 libecpg versions and libecpg_compat
Previous Message Ben Chobot 2010-02-04 23:22:34 Re: playr (or similar tool)?