Re: Help with creating function

From: cmasters <cmasters(at)nbnet(dot)nb(dot)ca>
To: pgsql-nov <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Help with creating function
Date: 2002-06-27 20:18:24
Message-ID: 20020627171824.A24556@grommit.mastersdaley.sys
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Greetings Stuart and Novices

On 27-06-02, Henshall, Stuart - WCP wrote:
> Is something like this what you wanted?
> create function my_concat(text,text,text) returns text as '
> select $1 || $2 || $3;
> ' language 'sql';
> hth,
> - Stuart
>

Although the above command was accepted, as I understand command syntax,
this would still force me to explicityly define each case as 'my_concat'
variables. This diesn't save my much typing :-(.

What I'm attempting to do is convert the following 'update' command to an
insert command. Is this possible?

for ease of use, we will assume that all var exist in the ~same~ table:

update table table1
set var4 =
upper (rpad (var1, 5, '-')) ||
lower (rpad (var2, 5, '-')) ||
lpad (var3, 5, '0'))
;

When I execute this as an update command, it works fine. However if I choose
to create a separate table for 'var4' and related reference fields, I will
have to ~insert~ the values into it.

As such I am attempting to create a function that can be called from any
legal command that will accomplish the same thing: chomp the variable(s) per
requirements and concatenate them into a new fourth variable (examples below).

Many thanks,
C-Cose Masters

> > -----Original Message-----
> > From: cmasters [mailto:cmasters(at)nbnet(dot)nb(dot)ca]
> >

... snip previous explanattion

> >
> > Example:
> >
> > Table "Client" contains
> > ID
> > SURNAME
> > GIVEN
> >
> > Table "author" contains
> > ID
> > SURNAME
> > GIVEN
> >
> > Table "nick" would contain
> > NICK (var4)
> > table of origin
> > SURNAME
> >

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Rory Campbell-Lange 2002-06-27 21:58:44 simplify case statement with function?
Previous Message James Kelty 2002-06-27 18:45:30 NFS/NAS