Parameterized trigger?

From: David Fetter <david(at)fetter(dot)org>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Parameterized trigger?
Date: 2003-09-09 23:13:43
Message-ID: 20030909231343.GA11442@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: sfpug

Kind people,

I'd like to set quite a few fields in a DB to be trimmed of leading
and trailing whitespace. My idea for doing it is to write a Pl/PgSQL
function that gets called on insert or update, but takes the
fieldname(s) as an array. Function looks something like this:

CREATE OR REPLACE FUNCTION trim_white(VARCHAR[]) RETURNS TRIGGER AS '
lower INTEGER;
upper INTEGER;
i INTEGER;
BEGIN
-- Get the upper & lower bounds somehow, and
FOR i = lower .. upper LOOP
NEW.$1[i] := btrim(NEW.$1[i], ' \t\n\r');
RETURN NEW;
END LOOP;
END;
' LANGUAGE 'plpgsql';

Then write triggers on each affected table that call trim_white.

Is this workable as designed? If not, what is? I'm running 7.3.4, if
that matters...

TIA for any hints on this :)

Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

Responses

Browse sfpug by date

  From Date Subject
Next Message Josh Berkus 2003-09-09 23:38:10 Re: Parameterized trigger?
Previous Message elein 2003-09-03 20:08:01 Re: PostgreSQL track for PHP Con West