Re: Verify a record has a column in a plpgsql trigger - Mailing list pgsql-general

From Tim Landscheidt
Subject Re: Verify a record has a column in a plpgsql trigger
Date
Msg-id m3fx5gmsc1.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to Verify a record has a column in a plpgsql trigger  (Mike Ginsburg <mginsburg@collaborativefusion.com>)
Responses Re: Verify a record has a column in a plpgsql trigger  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
Mike Ginsburg <mginsburg@collaborativefusion.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

pgsql-general by date:

Previous
From: Ben Chobot
Date:
Subject: Re: playr (or similar tool)?
Next
From: Rob Newton
Date:
Subject: libecpg versions and libecpg_compat