From: | Jesus Aneiros <aneiros(at)jagua(dot)cfg(dot)sld(dot)cu> |
---|---|
To: | Thomas Swan <tswan(at)olemiss(dot)edu> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Functions with Null Arguments? |
Date: | 2000-08-15 19:24:27 |
Message-ID: | Pine.LNX.4.10.10008151522080.23195-100000@jagua.cfg.sld.cu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I think you could use a function like the one below and use the following
select:
select id, name1, name2, prefname(foo) as pref from foo;
create function prefname(foo)
returns text as'
declare
foo alias for $1;
begin
if foo.name2 is null
then
return foo.name1;
else
return foo.name2;
end if;
end;'
language 'plpgsql';
--
Jesus Aneiros Sosa
mailto:aneiros(at)jagua(dot)cfg(dot)sld(dot)cu
http://jagua.cfg.sld.cu/~aneiros
On Tue, 15 Aug 2000, Thomas Swan wrote:
>
> Is there anyway way to get the following to work?
>
> table foo
> id | name1 | name2
> ---+---------+------
> 0 | Abe | NULL
> 1 | William | Bill
>
>
> create function prefname(text, text)
> returns text as'
> declare
> name1 alias for $1;
> name2 alias for $2;
> begin
> if name2 isnull
> then
> return name1;
> else
> return name2;
> end if;
> end;'
> language 'plpgsql';
>
> if I do
>
> I wind up with
>
> id | name1 | name2 | prefname
> ---+---------+-------+-----------
> 0 | Abe | NULL | NULL
> 1 | William | Bill | Bill
>
> instead of
>
> id | name1 | name2 | prefname
> ---+---------+-------+-----------
> 0 | Abe | NULL | Abe
> 1 | William | Bill | Bill
>
> I assume this has to do with Postgres not executing the function is one of
> the arguments is missing...
>
>
> -
> - Thomas Swan
> - Graduate Student - Computer Science
> - The University of Mississippi
> -
> - "People can be categorized into two fundamental
> - groups, those that divide people into two groups
> - and those that don't."
From | Date | Subject | |
---|---|---|---|
Next Message | Jesus Aneiros | 2000-08-15 19:37:17 | Re: % escape |
Previous Message | Stephan Szabo | 2000-08-15 19:11:41 | Re: copy from |