Re: Functions with Null Arguments? - Mailing list pgsql-sql

From DalTech - CTE
Subject Re: Functions with Null Arguments?
Date
Msg-id 008601c006b2$26763400$5911be86@cte.Dal.Ca
Whole thread Raw
In response to Functions with Null Arguments?  (Thomas Swan <tswan@olemiss.edu>)
Responses Re: Functions with Null Arguments?  (Thomas Swan <tswan-lst@tangent.ics.olemiss.edu>)
List pgsql-sql
I would try using COALESCE(list) which will return the first non-NULL in the list.
----- Original Message -----
Sent: Tuesday, August 15, 2000 3:18 AM
Subject: [SQL] Functions with Null Arguments?


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
select id, name1, name2, prefname(name1, name2) as pref from foo;

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."

pgsql-sql by date:

Previous
From: "Peter Mount"
Date:
Subject: Re: postgresql and java2
Next
From: "Adam Lang"
Date:
Subject: Re: copy from