| From: | "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | parameter in trigger function | 
| Date: | 2003-08-15 14:46:08 | 
| Message-ID: | 20030815144648.F0FC41CB1C1@koshin.dsl.systemec.nl | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Hello everyone,
Several columns in sereval tables in my DB should always be lowercase. 
I now have a simple function:
create or replace function code_lower() returns trigger as '
begin
	NEW.code := lower(NEW.code);
	return NEW;
end'
language 'plpgsql';
which I call with a trigger like this:
create trigger my_trigger
	before insert or update on my_table
	execute procedure code_lower();
This will successfully lower() a field named 'code' in the table 
'mytable' or any other table to which I point it. But some of my tables 
have fields which should be lower()ed that have names other than 
'code'. Writing a function for every of these field seems stupid, so I 
tried to give the trigger arguments. Code like this
NEW.$1 := lower(NEW.$1)
won't work, all I get is error messages :-( The doc says this should be 
OK (http://www.postgresql.org/docs/7.3/static/triggers.html) but Google 
mostly says the opposite. Is this possible at all? How do I read the 
TriggerData structure from whithin a pl/pgsql function?
TIA!
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Stephan Szabo | 2003-08-15 14:59:09 | Re: ADD FOREIGN KEY (was Re: [GENERAL] 7.4Beta) | 
| Previous Message | Stephan Szabo | 2003-08-15 14:38:30 | Re: [GENERAL] 7.4Beta |