Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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;
> -----------------------------------------


pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group