pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how to moce back in refcursor
2+ messages / 2 participants
[nested] [flat]

* how to moce back in refcursor
@ 2007-08-13 19:29 Christian Kindler <christian.kindler@gmx.net>
  2007-08-13 19:55 ` Re: how to moce back in refcursor Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Christian Kindler @ 2007-08-13 19:29 UTC (permalink / raw)
  To: pgsql-sql

Hi

I have never worked with cursors but for now I have to step back on special events to calculate a difference. So I have this sample code tested but I can not "move" in my cursor. I have lokke at docs but this didn't help me. Can you say how to declare my cursor to step back?

Thank You
Chris

PS code sample
create table fimi.eodbar(fi_id int8, market_id int8);
insert into fimi.eodbar values(322,200);

create or replace function fimi.test("fiid" int8) returns setof int as
$BODY$
DECLARE
  cur1 REFCURSOR;
  foo int;

BEGIN
  OPEN cur1 FOR execute('select market_id from fimi.eodbar where fi_id=' || "fiid");

   loop
    fetch cur1 into foo;

    if not found then
       exit ;
    else
       -- move -1 in cur1;
       fetch cur1 into foo;
       return next foo;
    end if;
   
   end loop;
close cur1; 

END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION fimi.getfoo(bpchar) OWNER TO fimi;

select * from fimi.test(322);
-- 
cu
Chris

GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: how to moce back in refcursor
  2007-08-13 19:29 how to moce back in refcursor Christian Kindler <christian.kindler@gmx.net>
@ 2007-08-13 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2007-08-13 19:55 UTC (permalink / raw)
  To: Christian Kindler <christian.kindler@gmx.net>; +Cc: pgsql-sql

"Christian Kindler" <christian.kindler@gmx.net> writes:
>        -- move -1 in cur1;

plpgsql supports that in CVS HEAD (8.3-to-be) but not in any existing
release.  You'll need to rethink your logic or do this from your
application rather than within plpgsql.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-08-13 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-13 19:29 how to moce back in refcursor Christian Kindler <christian.kindler@gmx.net>
2007-08-13 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox