Search Postgresql Archives

Using null or not null in function arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

maybe there is some built-in function for that?

b) If the input argument is NULL, then the corresponding select statement will be removed, so if it was not written.

I think, this is a common problem.

Thanks in advance and regards,
Igor Katson.

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux