pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
function returning a cursor and a scalar
3+ messages / 2 participants
[nested] [flat]

* function returning a cursor and a scalar
@ 2009-07-13 03:07  Surajit Bhattacharjee <surajitb@virtusa.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Surajit Bhattacharjee @ 2009-07-13 03:07 UTC (permalink / raw)
  To: pgsql-sql

I am new to Postgresql and am trying to write a function which will do a
search and return the first page of results along with the total number
of matches. How can I make my function return a cursor AND a scalar -
can I do the scalar as an OUT param and then make the function
explicitly RETURN a refcursor?

 

Surajit


---------------------------------------------------------------------------------------------

This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is intended for the addressee only. Any unauthorized disclosure, use, dissemination, copying, or distribution of this message or any of its attachments or the information contained in this e-mail, or the taking of any action based on it, is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return e-mail and delete this message.

---------------------------------------------------------------------------------------------

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

* Re: function returning a cursor and a scalar
@ 2009-07-13 18:21  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Surajit Bhattacharjee <surajitb@virtusa.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Alvaro Herrera @ 2009-07-13 18:21 UTC (permalink / raw)
  To: Surajit Bhattacharjee <surajitb@virtusa.com>; +Cc: pgsql-sql

Surajit Bhattacharjee wrote:
> I am new to Postgresql and am trying to write a function which will do a
> search and return the first page of results along with the total number
> of matches. How can I make my function return a cursor AND a scalar -
> can I do the scalar as an OUT param and then make the function
> explicitly RETURN a refcursor?

Why wouldn't you just use two OUT params?

BTW how do you plan on returning the number of matches?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



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

* Re: function returning a cursor and a scalar
@ 2009-07-14 15:21  Surajit Bhattacharjee <surajitb@virtusa.com>
  parent: Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Surajit Bhattacharjee @ 2009-07-14 15:21 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: pgsql-sql

Thanks much Alvaro. Didn't know I could do that.

For returning the matches, I am planning to run a separate count(*)
query with the original WHERE clause minus joins that are purely for
pulling addnl attributes from related entities. Only if this query
returns a positive count, I will run the query that actually gets the
data. I google'd some and couldn't find a way to avoid two queries.

Best Regards,
Surajit Bhattacharjee
__________________
Mobile: 508-277-9091
VOIP: 9032


-----Original Message-----
From: Alvaro Herrera [mailto:alvherre@commandprompt.com] 
Sent: Monday, July 13, 2009 2:22 PM
To: Surajit Bhattacharjee
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] function returning a cursor and a scalar

Surajit Bhattacharjee wrote:
> I am new to Postgresql and am trying to write a function which will do
a
> search and return the first page of results along with the total
number
> of matches. How can I make my function return a cursor AND a scalar -
> can I do the scalar as an OUT param and then make the function
> explicitly RETURN a refcursor?

Why wouldn't you just use two OUT params?

BTW how do you plan on returning the number of matches?

-- 
Alvaro Herrera
http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

---------------------------------------------------------------------------------------------

This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is intended for the addressee only. Any unauthorized disclosure, use, dissemination, copying, or distribution of this message or any of its attachments or the information contained in this e-mail, or the taking of any action based on it, is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return e-mail and delete this message.

---------------------------------------------------------------------------------------------



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


end of thread, other threads:[~2009-07-14 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-07-13 03:07 function returning a cursor and a scalar Surajit Bhattacharjee <surajitb@virtusa.com>
2009-07-13 18:21 ` Alvaro Herrera <alvherre@commandprompt.com>
2009-07-14 15:21   ` Surajit Bhattacharjee <surajitb@virtusa.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