Re: Using null or not null in function arguments

From: Igor Katson <descentspb(at)gmail(dot)com>
To: rod(at)iol(dot)ie
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using null or not null in function arguments
Date: 2009-01-23 12:33:03
Message-ID: 4979B8FF.9000803@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 dynamically as a string, then execute it
> using EXECUTE:
>
> http://www.postgresql.org/docs/8.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
>
>
>
>> b) If the input argument is NULL, then the corresponding select
>> statement will be removed, so if it was not written.
>>
>
> Likewise - something like
>
> if i_city_id is null then
> ... build statement...
> ... execute statement ...
> end if;
>
> HTH,
>
> Ray.
>
Thanks, Ray, but I see now, that I didn't explain the exact problem
correctly. The one is, that this kind of functions (search ones) can
have tens of arguments, and the more the amount of arguments is, the
more combinations of IF ... THEN conditionals will be present to build
the logic. If I have a couple of them, this can be easily handled
through IF THEN, or dynamic statements, but what if I have tens of 'em?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Figueiredo Jr. 2009-01-23 12:34:01 Re: How to convert ByteA to Large Objects
Previous Message Raymond O'Donnell 2009-01-23 12:14:42 Re: Using null or not null in function arguments