Search Postgresql Archives

Re: IN clause in a cursor

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

 



Nevermind. I used:

OPEN test FOR EXECUTE 'SELECT a, b, c FROM tbl WHERE d IN ' values;

Nik wrote:
> I have a dynamic set of clauses that I would like to use in the cursor.
> Is there a way to achieve this using the "IN" clause and a string, or
> multiple "OR" clauses coupled with strings.
>
> This doesn't work, but it's an example of what I'm trying to do.
>
> -----------------------------------------
> DECLARE
> test refcursor;
> values varchar;
>
> BEGIN
> -- This will be dynamically generated
> values := '(1, 2, 3)';
>
> OPEN test FOR SELECT a, b, c FROM tbl WHERE d IN values;
> CLOSE test;
>
> END;
> -----------------------------------------
>
> or
>
> -----------------------------------------
> DECLARE
> test refcursor;
> values varchar;
>
> BEGIN
> -- This will be dynamically generated
> values := '(d=1 OR d=2 OR d=3)';
>
> OPEN test FOR SELECT a, b, c FROM tbl WHERE values;
> CLOSE test;
> 
> END;
> -----------------------------------------



[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