Re: IN clause in a cursor

From: "Nik" <XLPizza(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: IN clause in a cursor
Date: 2006-11-28 19:57:10
Message-ID: 1164743830.684446.151370@j44g2000cwa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2006-11-28 20:01:03 Re: Only MONO/WinForms is a way to go
Previous Message Thomas Kellerer 2006-11-28 19:50:43 Re: Only MONO/WinForms is a way to go