pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to write cursors
3+ messages / 2 participants
[nested] [flat]

* How to write cursors
@ 2012-04-03 07:44  La Chi <the_man.inmee@yahoo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: La Chi @ 2012-04-03 07:44 UTC (permalink / raw)
  To: pgsql-sql

Hello everyone,

i have created this function in which i simply want to display a column values through a cursor , but unfortunately i am not getting the column values , this function is showing me simple column name but not the  fields in column.

CREATE OR REPLACE FUNCTION foo(id int) returns table(user_id int) as
$BODY$
DECLARE r int;
DECLARE rs cursor for Select userid from customer where area ='new_york';
BEGIN
open rs ;
fetch next from rs into r;
while (found) loop
fetch Next from rs into r;
END loop; 
close rs;  
END;
$BODY$
LANGUAGE plpgsql;


i simply want to show all the record from customer table where area is New York but with the help of cursors.
thanks

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

* how to write cursors
@ 2012-04-04 07:30  La Chi <the_man.inmee@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: La Chi @ 2012-04-04 07:30 UTC (permalink / raw)
  To: pgsql-sql

hi every one

i have created this simple function which returns a column of table , i have used simple SELECT statement , i simply want to know how can i achieve the same task with the help of cursor

CREATE OR REPLACE FUNCTION foo(id int)
returns table(cust_id int) as
$BODY$

BEGIN
       
return query Select userid from customer where proname ='shampoo';
END;
$BODY$
LANGUAGE plpgsql;

how can i write a cursor which should return all the custid who had proname shampoo . i shall be very thankful to you 


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

* Re: how to write cursors
@ 2012-04-04 07:36  Pavel Stehule <pavel.stehule@gmail.com>
  parent: La Chi <the_man.inmee@yahoo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Pavel Stehule @ 2012-04-04 07:36 UTC (permalink / raw)
  To: La Chi <the_man.inmee@yahoo.com>; +Cc: pgsql-sql

Hello

use a refcursors

http://www.postgresql.org/docs/9.1/static/plpgsql-cursors.html

Regards

Pavel Stehule

2012/4/4 La Chi <the_man.inmee@yahoo.com>:
> hi every one
>
> i have created this simple function which returns a column of table , i have
> used simple SELECT statement , i simply want to know how can i achieve the
> same task with the help of cursor
>
> CREATE OR REPLACE FUNCTION foo(id int)
> returns table(cust_id int) as
> $BODY$
>
> BEGIN
>
> return query Select userid from customer where proname ='shampoo';
> END;
> $BODY$
> LANGUAGE plpgsql;
>
> how can i write a cursor which should return all the custid who had proname
> shampoo . i shall be very thankful to you
>



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


end of thread, other threads:[~2012-04-04 07:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-04-03 07:44 How to write cursors La Chi <the_man.inmee@yahoo.com>
2012-04-04 07:30 how to write cursors La Chi <the_man.inmee@yahoo.com>
2012-04-04 07:36 ` Re: how to write cursors Pavel Stehule <pavel.stehule@gmail.com>

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