Re: How to declare cursor if tablename is a variable?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: hu js <hu(dot)bill2005(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to declare cursor if tablename is a variable?
Date: 2007-03-14 14:09:34
Message-ID: 20070314140934.GA7086@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Mar 14, 2007 at 08:14:07AM +0000, hu js wrote:
> CREATE or replace function geo_polygon(tablename varchar) RETURNS
> [...]
> cur_obj CURSOR FOR SELECT mrc_xy_position FROM tablename;
> cur_point CURSOR FOR SELECT x,y FROM tablename where mrc_xy_position =
> objectid;
>
> Error if call the function. Neither to use “execute” . Who can solve
> it? Thanks!

Are you sure you need to use cursors? Can you not build the query
strings and use EXECUTE or "FOR variable IN EXECUTE query LOOP"?

--
Michael Fuhr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message T E Schmitz 2007-03-14 14:45:21 Re: import CSV file
Previous Message Achilleas Mantzios 2007-03-14 13:12:05 Re: reindex database