Re: Any reason not to return row_count in cursor of plpgsql?

Lists: pgsql-hackers
From: laser <laserlist(at)pgsqldb(dot)com>
To: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Any reason not to return row_count in cursor of plpgsql?
Date: 2008-07-21 01:39:54
Message-ID: 4883E8EA.6020702@pgsqldb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

hi all,

I read the code that it seems easy for the cursor in plpgsql to return
ROW_COUNT after
MOVE LAST etc. The SPI_processed variable already there, but didn't put
it into estate
structure, any reason for that?

thanks and best regards

-laser


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: laser <laserlist(at)pgsqldb(dot)com>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2008-12-15 23:42:55
Message-ID: 200812152342.mBFNgtM27630@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

laser wrote:
> hi all,
>
> I read the code that it seems easy for the cursor in plpgsql to return
> ROW_COUNT after
> MOVE LAST etc. The SPI_processed variable already there, but didn't put
> it into estate
> structure, any reason for that?

[ Sorry for the delay.]

Would some tests how Oracle behaves in this case?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: laser <laserlist(at)pgsqldb(dot)com>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-03-27 02:26:35
Message-ID: 200903270226.n2R2QZC10054@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

laser wrote:
> hi all,
>
> I read the code that it seems easy for the cursor in plpgsql to return
> ROW_COUNT after
> MOVE LAST etc. The SPI_processed variable already there, but didn't put
> it into estate
> structure, any reason for that?
>
> thanks and best regards

Sorry, we have decided against this change because it might break
existing applications.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: bruce(at)momjian(dot)us (Bruce Momjian), pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-03-27 10:45:27
Message-ID: 877i2bi6rc.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>>>> "Bruce" == Bruce Momjian <bruce(at)momjian(dot)us> writes:

>> hi all,
>>
>> I read the code that it seems easy for the cursor in plpgsql to
>> return ROW_COUNT after MOVE LAST etc. The SPI_processed variable
>> already there, but didn't put it into estate structure, any reason
>> for that?
>>
>> thanks and best regards

Bruce> Sorry, we have decided against this change because it might
Bruce> break existing applications.

As they say on wikipedia, [citation needed]

GET DIAGNOSTICS ROW_COUNT is documented as working for all commands;
if it doesn't work for MOVE (and FETCH), that's a bug. It might be one
that's not appropriate to backpatch, but that's no excuse for not
fixing it in a new release.

It's especially egregious in that MOVE _does_ set FOUND.

diff -c -r1.235 pl_exec.c
*** pl_exec.c 23 Feb 2009 10:03:22 -0000 1.235
--- pl_exec.c 27 Mar 2009 10:44:08 -0000
***************
*** 3368,3373 ****
--- 3368,3375 ----
exec_set_found(estate, n != 0);
}

+ estate->eval_processed = n;
+
return PLPGSQL_RC_OK;
}

--
Andrew (irc:RhodiumToad)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: bruce(at)momjian(dot)us (Bruce Momjian), pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-03-27 19:04:08
Message-ID: 2592.1238180648@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> GET DIAGNOSTICS ROW_COUNT is documented as working for all commands;
> if it doesn't work for MOVE (and FETCH), that's a bug.

Or a documentation problem. I don't see any claim that it works for
"all commands" anyway.

regards, tom lane


From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: bruce(at)momjian(dot)us (Bruce Momjian), pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-03-27 20:59:29
Message-ID: 87hc1efzri.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
>> GET DIAGNOSTICS ROW_COUNT is documented as working for all commands;
>> if it doesn't work for MOVE (and FETCH), that's a bug.

Tom> Or a documentation problem. I don't see any claim that it works for
Tom> "all commands" anyway.

"This command allows retrieval of system status indicators. Each item
is a key word identifying a state value to be assigned to the
specified variable (which should be of the right data type to receive
it). The currently available status items are ROW_COUNT, the number of
rows processed by the last SQL command sent down to the SQL engine,
and RESULT_OID, the OID of the last row inserted by the most recent
SQL command. Note that RESULT_OID is only useful after an INSERT
command into a table containing OIDs."

The idea that fetch/move should _intentionally_ not set ROW_COUNT is
beyond ludicrous.

--
Andrew.


From: David Fetter <david(at)fetter(dot)org>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-03-27 21:05:44
Message-ID: 20090327210544.GD19621@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Mar 27, 2009 at 08:59:29PM +0000, Andrew Gierth wrote:
> >>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
> > Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> >> GET DIAGNOSTICS ROW_COUNT is documented as working for all commands;
> >> if it doesn't work for MOVE (and FETCH), that's a bug.
>
> Tom> Or a documentation problem. I don't see any claim that it works for
> Tom> "all commands" anyway.
>
> "This command allows retrieval of system status indicators. Each item
> is a key word identifying a state value to be assigned to the
> specified variable (which should be of the right data type to receive
> it). The currently available status items are ROW_COUNT, the number of
> rows processed by the last SQL command sent down to the SQL engine,
> and RESULT_OID, the OID of the last row inserted by the most recent
> SQL command. Note that RESULT_OID is only useful after an INSERT
> command into a table containing OIDs."
>
> The idea that fetch/move should _intentionally_ not set ROW_COUNT is
> beyond ludicrous.

It's a flat-out bug not to have FETCH/MOVE set this.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any reason not to return row_count in cursor of plpgsql?
Date: 2009-04-02 19:20:55
Message-ID: 200904021920.n32JKtF00619@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Thanks, patch applied.

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

Andrew Gierth wrote:
> >>>>> "Bruce" == Bruce Momjian <bruce(at)momjian(dot)us> writes:
>
> >> hi all,
> >>
> >> I read the code that it seems easy for the cursor in plpgsql to
> >> return ROW_COUNT after MOVE LAST etc. The SPI_processed variable
> >> already there, but didn't put it into estate structure, any reason
> >> for that?
> >>
> >> thanks and best regards
>
> Bruce> Sorry, we have decided against this change because it might
> Bruce> break existing applications.
>
> As they say on wikipedia, [citation needed]
>
> GET DIAGNOSTICS ROW_COUNT is documented as working for all commands;
> if it doesn't work for MOVE (and FETCH), that's a bug. It might be one
> that's not appropriate to backpatch, but that's no excuse for not
> fixing it in a new release.
>
> It's especially egregious in that MOVE _does_ set FOUND.
>
> diff -c -r1.235 pl_exec.c
> *** pl_exec.c 23 Feb 2009 10:03:22 -0000 1.235
> --- pl_exec.c 27 Mar 2009 10:44:08 -0000
> ***************
> *** 3368,3373 ****
> --- 3368,3375 ----
> exec_set_found(estate, n != 0);
> }
>
> + estate->eval_processed = n;
> +
> return PLPGSQL_RC_OK;
> }
>
> --
> Andrew (irc:RhodiumToad)

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +