From: | "ben sewell" <mosherben(at)gmail(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | postgresql wildcard when parameter is -1 |
Date: | 2006-08-25 06:42:46 |
Message-ID: | bf6c74d80608242342q61472af1h72e799c2765edd5@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi Michael,
thanks for your reply. I've seen that % is the wildcard in postgres, so
couldnt I just do an if statement to overwrite the parameter? Also, I'm
interested in a wildcard for dates. Would that be %%/%%/%%%%?
Cheers,
Ben
On 8/24/06, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
>
> On Thu, Aug 24, 2006 at 09:01:06AM +0100, ben sewell wrote:
> > I have a question, when a parameter is recieved as -1 (as an integer
> from
> > Access), I would like that parameter to be a wildcard. The logic is that
> I
> > am sending the primary key for a table to postgres for a report but when
> > there hasnt been a value chosen in the combo box -1 is sent to postgres
> so
> > it would mean that that parameter don't apply in the SP, otherwise if it
> did
> > have another value then the parameter would be used to do some filtering
> > (joins).
>
> You'll need to rewrite the query to handle the "wildcard". One way
> would be with an expression like this:
>
> WHERE (param = -1 OR param = column_name) AND ...
>
> The parentheses are important if you have multiple expressions.
>
> Another way would be to build the query string dynamically, adding
> only the parts you need, then EXECUTE it (assuming PL/pgSQL; do the
> equivalent in other languages). See "Executing Dynamic Commands"
> in the PL/pgSQL documentation:
>
>
> http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
>
> --
> Michael Fuhr
>
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2006-08-25 07:37:25 | Re: postgresql wildcard when parameter is -1 |
Previous Message | Andrej Ricnik-Bay | 2006-08-25 06:14:17 | Re: phppgadmin not working under v. 8.1 |