pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
cursor "x" does not exist
5+ messages / 4 participants
[nested] [flat]

* cursor "x" does not exist
@ 2018-04-14 14:44  Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Bob Jones @ 2018-04-14 14:44 UTC (permalink / raw)
  To: pgsql-general

Hello,

My apologies if I'm being incredibly stupid here, but I've reviewed
what the docs have to say about naming portals and I still can't see
where I'm going wrong here ?

CREATE FUNCTION blah(v_id text,v_cursor refcursor) RETURNS refcursor
AS
$BODY$
BEGIN
OPEN v_cursor FOR SELECT *  FROM blah where idcol=v_id;
RETURN v_cursor;
END;
$BODY$
LANGUAGE plpgsql;

The select query in here does return data, so I know the output from
below is certainly expected to return something.

BEGIN;
SELECT blah('A','B');
blah
--------------------------
 B
(1 row)

FETCH ALL IN B;
ERROR:  cursor "b" does not exist



P.S. As a side-question, if anyone here has experience in using
Postgres as a backend to PHP, are refcursors the way to go or should I
be thinking of SETOF or other return styles ?




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

* Re: cursor "x" does not exist
@ 2018-04-14 15:38  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2018-04-14 15:38 UTC (permalink / raw)
  To: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>; +Cc: pgsql-general

Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com> writes:
> My apologies if I'm being incredibly stupid here, but I've reviewed
> what the docs have to say about naming portals and I still can't see
> where I'm going wrong here ?

I think you're forgetting to double-quote an upper case identifier.

> FETCH ALL IN B;
> ERROR:  cursor "b" does not exist

The cursor is named "B" not "b", but B without quotes folds to the latter.

			regards, tom lane




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

* Re: cursor "x" does not exist
@ 2018-04-14 16:36  Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Bob Jones @ 2018-04-14 16:36 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

On 14 April 2018 at 16:38, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com> writes:
>> My apologies if I'm being incredibly stupid here, but I've reviewed
>> what the docs have to say about naming portals and I still can't see
>> where I'm going wrong here ?
>
> I think you're forgetting to double-quote an upper case identifier.
>
>> FETCH ALL IN B;
>> ERROR:  cursor "b" does not exist
>
> The cursor is named "B" not "b", but B without quotes folds to the latter.
>
>                         regards, tom lane


Thank you tom for showing me the error in my ways.

Now where's that dunce cap gone ?  Maybe I don't deserve to use
anything better than MySQL.   ;-)




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

* Re: cursor "x" does not exist
@ 2018-04-14 16:40  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Adrian Klaver @ 2018-04-14 16:40 UTC (permalink / raw)
  To: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

On 04/14/2018 09:36 AM, Bob Jones wrote:
> On 14 April 2018 at 16:38, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com> writes:
>>> My apologies if I'm being incredibly stupid here, but I've reviewed
>>> what the docs have to say about naming portals and I still can't see
>>> where I'm going wrong here ?
>>
>> I think you're forgetting to double-quote an upper case identifier.
>>
>>> FETCH ALL IN B;
>>> ERROR:  cursor "b" does not exist
>>
>> The cursor is named "B" not "b", but B without quotes folds to the latter.
>>
>>                          regards, tom lane
> 
> 
> Thank you tom for showing me the error in my ways.
> 
> Now where's that dunce cap gone ?  Maybe I don't deserve to use
> anything better than MySQL.   ;-)

Or read the below and be illuminated:)

https://www.postgresql.org/docs/10/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




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

* Re: cursor "x" does not exist
@ 2018-04-15 12:15  rob stone <floriparob@gmail.com>
  parent: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: rob stone @ 2018-04-15 12:15 UTC (permalink / raw)
  To: Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>; pgsql-general

Hello Bob,

On Sat, 2018-04-14 at 15:44 +0100, Bob Jones wrote:
> Hello,
> 
> 
> 
> P.S. As a side-question, if anyone here has experience in using
> Postgres as a backend to PHP, are refcursors the way to go or should
> I
> be thinking of SETOF or other return styles ?
> 


If you have a business requirement along the lines of "display all
outstanding orders for a customer" it is best to create a view that
serves that purpose. Then all you need to code is a "select * from
v_outstanding_orders where customer_id = $1";
If there are any outstanding orders you can page through the
associative array returned by the query in order to display the
results.

HTH,
Rob






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


end of thread, other threads:[~2018-04-15 12:15 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-14 14:44 cursor "x" does not exist Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
2018-04-14 15:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-14 16:36   ` Bob Jones <r.a.n.d.o.m.d.e.v.4+postgres@gmail.com>
2018-04-14 16:40     ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-04-15 12:15 ` rob stone <floriparob@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