Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-26 Thread Bryn Llewellyn
> adrian.kla...@aklaver.com wrote: > >> b...@yugabyte.com replied to laurenz.a...@cybertec.at: >> >> Thanks for the link to your SQL file at the line where you get the row count >> in the way that you describe... I noted that neither of these functions has >

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-23 Thread Bryn Llewellyn
n and how to use it, > not how I went about implementing it. You are interpreting too much. I just > wanted to show you a case where scrollable cursors can be useful. > >> The upshot, therefore, is that I'm afraid that I can only guess at why you >> use "o

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-22 Thread Adrian Klaver
~200 lines). And I saw that you use the cursor mechanism that we're discussing here in only one other function, "db_migrate_refresh()" (~480 lines). But this second one doesn't use the "move forward all" device to get a row count. I looked only at these two functions.

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-22 Thread Laurenz Albe
to show you a case where scrollable cursors can be useful. > The upshot, therefore, is that I'm afraid that I can only guess at why you > use "open, fetch, close" > on a refcursor rather than an ordinary cursor for loop. After all, you use > the technique only > to tr

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-22 Thread Bryn Llewellyn
igrate_refresh()" (~480 lines). But this second one doesn't use the "move forward all" device to get a row count. I looked only at these two functions. I noted that neither of these functions has a refcursor formal argument and that, rather, you open (i.e. create) each of

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-21 Thread Laurenz Albe
equivalent of > "refcursor". > So I had never come across use cases where this was beneficial. I wanted, > therefore, > to hear about some. I thought that insights here would help me understand the > mechanics. > But I didn't get anything beyond "Scrollability is

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-20 Thread Adrian Klaver
f testing before responding to make sure that the mental model that I've formed for myself is consistent with these. You may not be interested in what follows. But, anyway, here goes. — I happen to have many years of experience with Oracle Database and PL/SQL. The latter has analogous feature

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-20 Thread Bryn Llewellyn
with psychology. I probably can't explain this convincingly. That's why it's taken me a long time to respond. I also had to do lots of testing before responding to make sure that the mental model that I've formed for myself is consistent with these. You may not be inte

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-17 Thread Peter J. Holzer
On 2023-03-16 11:52:47 +0100, Dominique Devienne wrote: > On Thu, Mar 16, 2023 at 11:15 AM Pavel Stehule > wrote: > čt 16. 3. 2023 v 9:55 odesílatel Dominique Devienne > napsal: > That's a nice way to put it Pavel. > And to have it both ways, use COPY in binary protocol?

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Adrian Klaver
/SQL's packages, you have no mechanism to hold the opened cursor variable between successive server calls.)" What part of this: CREATE TABLE test (col text); INSERT INTO test VALUES ('123'); CREATE FUNCTION reffunc(refcursor) RETURNS refcursor AS ' BEGIN OPEN $1 FOR SE

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Pavel Stehule
čt 16. 3. 2023 v 11:52 odesílatel Dominique Devienne napsal: > On Thu, Mar 16, 2023 at 11:15 AM Pavel Stehule > wrote: > >> čt 16. 3. 2023 v 9:55 odesílatel Dominique Devienne >> napsal: >> >>> On Thu, Mar 16, 2023 at 9:23 AM Pavel Stehule >>> wrote: >>> čt 16. 3. 2023 v 9:18 odesílatel D

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Dominique Devienne
On Thu, Mar 16, 2023 at 11:15 AM Pavel Stehule wrote: > čt 16. 3. 2023 v 9:55 odesílatel Dominique Devienne > napsal: > >> On Thu, Mar 16, 2023 at 9:23 AM Pavel Stehule >> wrote: >> >>> čt 16. 3. 2023 v 9:18 odesílatel Dominique Devienne >>> napsal: >>> [...] depends on what you value in

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Pavel Stehule
čt 16. 3. 2023 v 9:55 odesílatel Dominique Devienne napsal: > On Thu, Mar 16, 2023 at 9:23 AM Pavel Stehule > wrote: > >> čt 16. 3. 2023 v 9:18 odesílatel Dominique Devienne >> napsal: >> >>> [...] depends on what you value in a particular situation, latency or >>> throughput. --DD >>> >> >> cu

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Dominique Devienne
On Thu, Mar 16, 2023 at 9:23 AM Pavel Stehule wrote: > čt 16. 3. 2023 v 9:18 odesílatel Dominique Devienne > napsal: > >> [...] depends on what you value in a particular situation, latency or >> throughput. --DD >> > > cursors are optimized for minimal cost of first row, queries are optimized >

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Pavel Stehule
čt 16. 3. 2023 v 9:18 odesílatel Dominique Devienne napsal: > On Thu, Mar 16, 2023 at 6:48 AM Laurenz Albe > wrote: > >> As we wrote, some of us think that cursors are useful, and we tried to >> explain why we think that. If you don't think that cursors are useful, >> don't use them. We are no

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-16 Thread Dominique Devienne
On Thu, Mar 16, 2023 at 6:48 AM Laurenz Albe wrote: > As we wrote, some of us think that cursors are useful, and we tried to > explain why we think that. If you don't think that cursors are useful, > don't use them. We are not out to convince you otherwise. > Perhaps OT (I only skimed this thr

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Laurenz Albe
Well, it is simple. As we wrote, some of us think that cursors are useful, and we tried to explain why we think that. If you don't think that cursors are useful, don't use them. We are not out to convince you otherwise. Yours, Laurenz Albe

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Bryn Llewellyn
rse, from being able to use the right vocabulary to express what confused me. It's very much clearer now than when I started this thread, about twenty-four hours ago. Here's (some of) what I believe that I now understand. "refcursor" is a base type, listed in pg_type. Th

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Bryn Llewellyn
> adrian.kla...@aklaver.com wrote: > >> b...@yugabyte.com wrote: >> >>> laurenz.a...@cybertec.at wrote: >>> >>> You seem to think that a client request corresponds to a single database >>> request >> >> …I can’t picture a concrete use case where, not withstanding the "where" >> restriction th

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Adrian Klaver
On 3/15/23 13:37, Bryn Llewellyn wrote: laurenz.a...@cybertec.at wrote: Re « You seem to think that a client request corresponds to a single database request », I meant no more than what psql models when you hit "return"after terminating an ordinary SQL statement with semi-colon (i.e. not a

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Bryn Llewellyn
> laurenz.a...@cybertec.at wrote: > >> b...@yugabyte.com wrote: >> >> Section "43.7. Cursors” in the PL/pgSQL chapter of the doc >> (www.postgresql.org/docs/current/plpgsql-cursors.html#PLPGSQL-CURSOR-DECLARATIONS) >> starts with this: >> >> « >> [...] >> A more interesting usage is to return a

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-15 Thread Laurenz Albe
On Tue, 2023-03-14 at 17:50 -0700, Bryn Llewellyn wrote: > Section "43.7. Cursors” in the PL/pgSQL chapter of the doc > (www.postgresql.org/docs/current/plpgsql-cursors.html#PLPGSQL-CURSOR-DECLARATIONS) > starts with this: > > « > [...] > A more interesting usage is to return a reference to a cur

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-14 Thread Adrian Klaver
's owned by a role that can select from the relevant table(s) that returns refcursor. And I called it from a subprogram that's owned by a role that cannot select from the relevant table(s) to loop through the rows. But I can't convince myself that this division of labor is useful.

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-14 Thread Bryn Llewellyn
er to read the rows. This provides an efficient way to return large row >> sets from functions. >> » >> On its face, it seems to make sense. And I’ve written a few proof-of-concept >> tests. For example, I wrote a “security definer” function that's owned by a >> ro

Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-14 Thread Adrian Klaver
of-of-concept tests. For example, I wrote a “security definer” function that's owned by a role that can select from the relevant table(s) that returns refcursor. And I called it from a subprogram that's owned by a role that cannot select from the relevant table(s) to loop through the ro

Is the PL/pgSQL refcursor useful in a modern three-tier app?

2023-03-14 Thread Bryn Llewellyn
ote a “security definer” function that's owned by a role that can select from the relevant table(s) that returns refcursor. And I called it from a subprogram that's owned by a role that cannot select from the relevant table(s) to loop through the rows. But I can't convince myself th

Re: Refcursor

2021-03-15 Thread Laurenz Albe
On Mon, 2021-03-15 at 13:58 +0200, Yambu wrote: > May I know why the below takes so long? > > > BEGIN; > select * from func1() ; > fetch all from ""; > end; > > Select * from func1() ; on its own is very fast The second just fetches a cursor for the query, the first executes the query.

Refcursor

2021-03-15 Thread Yambu
Hi I new to cursors May I know why the below takes so long? BEGIN; select * from func1() ; fetch all from ""; end; Select * from func1() ; on its own is very fast