Re: Help with creating function - Mailing list pgsql-novice

From cmasters
Subject Re: Help with creating function
Date
Msg-id 20020627171824.A24556@grommit.mastersdaley.sys
Whole thread Raw
In response to Re: Help with creating function  ("Henshall, Stuart - WCP" <SHenshall@westcountrypublications.co.uk>)
List 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@nbnet.nb.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
> >



pgsql-novice by date:

Previous
From: "James Kelty"
Date:
Subject: NFS/NAS
Next
From: Rory Campbell-Lange
Date:
Subject: simplify case statement with function?