Re: cursor with dinamic string

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Luca Santaniello <luca(dot)santaniello(dot)81(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cursor with dinamic string
Date: 2011-03-25 12:37:24
Message-ID: AANLkTimqrCpEb=XVwQXrmEB-jOFWpA06cCDGAqssMyzf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2011/3/25 Luca Santaniello <luca(dot)santaniello(dot)81(at)gmail(dot)com>:
> Hi all,
>
> I need use dinamic string for my cursor... My code is:
>
> query varchar := 'field1, field2 from ''' || tableName ||''' ........; //has
> dinamic params
>

use a FOR EXECUTE statement

FOR r IN EXECUTE 'SELECT .. FROM ' || quote_ident(tableName) || ' ....'
LOOP
...

you can use OPEN FOR EXECUTE too, but FOR statement is preferable

Regards

Pavel Stehule

http://www.postgresql.org/docs/9.0/interactive/plpgsql-cursors.html#PLPGSQL-CURSOR-OPENING

> then I create cursor...
>
> myCursor CURSOR FOR SELECT query;
>
> I compile my function but when i run it I obtain error...
>
> ERROR:  invalid input syntax for integer: ......
> CONTEXT:  PL/pgSQL function "my_function" line 72 at FETCH
>
> If I use static string, I don't have problems!!!
>
> Can I solve it?
>
> Thanks in advance
>
> --
> Luca Santaniello
> email: luca(dot)santaniello(dot)81(at)gmail(dot)com
> skype: luca.santaniello
> msn: luketto81(at)hotmail(dot)com
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Luca Santaniello 2011-03-25 13:18:43 Re: cursor with dinamic string
Previous Message Luca Santaniello 2011-03-25 12:07:25 cursor with dinamic string