Re: pl/tcl trigger question

From: "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Subject: Re: pl/tcl trigger question
Date: 2003-09-01 11:25:56
Message-ID: 20030901112644.33A411CB1CF@koshin.dsl.systemec.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Op 26 Aug 2003 (12:38), schreef Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>:
> On Tue, 2003-08-26 at 07:28, Jules Alberts wrote:
> > Hello everyone,
> >
> > I'm working on a tiny trigger function that needs to ensure that all
> > values entered in a field are lowercase'd. I can't use pl/pgsql
> > because I have a dozen different columns (with different names) that
> > need a trigger that does this and pl'pgsql can't expand variable names
> > to fieldnames. Writing a dozen functions (one per columnname) is /way/
> > too blunt so I tried pl/tcl (which I don't know):

<bad attempt snipped>

> You'll need a function a bit more complex than this, but to do what your
> trying to do in the function above the function would be written as:
>
> create or replace function my_lowercase() returns trigger as '
> set NEW($1) [string tolower $NEW($1)]
> return [array get NEW]' language 'pltcl';
>
> Hope this helps, please post the final results when you get there.

Hi Robert,

It works great, thanks a lot! There is one little issue though: when I
insert null values, the function fails. I think I can work around this
by giving the columns a default value of '' in my table design, but I
would like a more defensive approach, I.E. having my_lowercase() check
for null values.

Thanks again for any help, and sorry if I'm asking basic TCL questions,
I don't know the language. Do you happen to know a good site where the
language is explained? All I googled was about creating widgets, GUI
stuff :-(

> Robert Treat

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Thomas 2003-09-01 11:36:06 Re: About GPL and proprietary software
Previous Message Joost Kremers 2003-09-01 10:24:29 delivering database stand-alone