Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Sam Mason
On Fri, Jan 23, 2009 at 06:32:17PM +0300, Igor Katson wrote: > Sam, I'm not sure if this is correct to do that, as you I don't want to > remember what will happen, if you use NULL = NULL or upper(NULL) etc.: > > WHERE >COALESCE(city_id = i_city_id, TRUE) AND >COALESCE(edu_id = i_edu_id,

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Igor Katson
Michael Glaesemann wrote: On Jan 23, 2009, at 10:11 , Igor Katson wrote: That one is awesome, thanks, I completely forgot about CASE statement. The search func now looks as follows, and works perfectly: CREATE OR REPLACE FUNCTION isocial_user_func.search_users (i_city_id int, i_edu_id int, i

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Michael Glaesemann
On Jan 23, 2009, at 10:11 , Igor Katson wrote: That one is awesome, thanks, I completely forgot about CASE statement. The search func now looks as follows, and works perfectly: CREATE OR REPLACE FUNCTION isocial_user_func.search_users (i_city_id int, i_edu_id int, i_firstname text, i_lastnam

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Igor Katson
Sam Mason wrote: On Fri, Jan 23, 2009 at 02:16:34PM +0300, Igor Katson wrote: a) If the input argument is NULL, then the corresponding select statement will change from column = arg to column IS NULL I think you want to use the IS [NOT] DISTINCT FROM operator. It works like the = an

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Sam Mason
On Fri, Jan 23, 2009 at 02:16:34PM +0300, Igor Katson wrote: > a) If the input argument is NULL, then the corresponding select > statement will change from > > column = arg > to > column IS NULL I think you want to use the IS [NOT] DISTINCT FROM operator. It works like the = and <> operators. i

Resp.: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Osvaldo Kussama
2009/1/23, Igor Katson : > I have a row search function, smth like > > CREATE OR REPLACE FUNCTION user_func.search_users > (i_city_id int, i_edu_id int, i_first_name text, i_last_name text, > limit_ int, offset_ int) RETURNS SETOF user.user AS $$ > . SELECT * FROM user WHERE > city_id = i

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Igor Katson
Raymond O'Donnell wrote: On 23/01/2009 11:16, Igor Katson wrote: How do I write a function without complex logic, which will do: a) If the input argument is NULL, then the corresponding select statement will change from column = arg to column IS NULL You could build your statement dy

Re: [GENERAL] Using null or not null in function arguments

2009-01-23 Thread Raymond O'Donnell
On 23/01/2009 11:16, Igor Katson wrote: > How do I write a function without complex logic, which will do: > a) If the input argument is NULL, then the corresponding select > statement will change from > > column = arg > to > column IS NULL You could build your statement dynamically as a string,

[GENERAL] Using null or not null in function arguments

2009-01-23 Thread Igor Katson
I have a row search function, smth like CREATE OR REPLACE FUNCTION user_func.search_users (i_city_id int, i_edu_id int, i_first_name text, i_last_name text, limit_ int, offset_ int) RETURNS SETOF user.user AS $$ . SELECT * FROM user WHERE city_id = i_city_id ... $$ language plpgsql; How