Thread: execute command tag including affected rows count

execute command tag including affected rows count

From
Kris Jurka
Date:
Would it be possible to have the command completion tag for EXECUTE return
the affected row count?  The JDBC API says you should be able to get the
affected row count for any statement and I'm working on integrating a
patch that transforms regular statements to server side prepared
statements, and I'm stuck on this issue.

CREATE TABLE t (a int);
INSERT INTO t VALUES (1);
INSERT INTO t VALUES (2);
PREPARE mystatement AS DELETE FROM t;
EXECUTE mystatement;

would ideally return "EXECUTE 2"

Kris Jurka



Re: execute command tag including affected rows count

From
Neil Conway
Date:
On 21-Mar-04, at 11:39 AM, Kris Jurka wrote:
> Would it be possible to have the command completion tag for EXECUTE 
> return
> the affected row count?

Yes, this has been suggested before -- for example:

http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg26787.html

I agree it would be a good idea, although I can't recall what the 
conclusion of the previous discussions was -- did anyone raise any 
critical objections to this?

-Neil



Re: execute command tag including affected rows count

From
Tom Lane
Date:
Neil Conway <neilc@samurai.com> writes:
> On 21-Mar-04, at 11:39 AM, Kris Jurka wrote:
>> Would it be possible to have the command completion tag for EXECUTE 
>> return
>> the affected row count?

> Yes, this has been suggested before -- for example:

> http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg26787.html

> I agree it would be a good idea, although I can't recall what the 
> conclusion of the previous discussions was -- did anyone raise any 
> critical objections to this?

The previous discussion concluded that EXECUTE should return the command
tag of the executed command --- eg, "UPDATE n" not "EXECUTE n".  Without
this, you cannot for example sensibly cope with both the INSERT and
UPDATE tag formats.

Not sure what it takes internally to the backend to make this happen
... but IIRC there already is provision for utility commands to override
their default tag, so I hope that it would be a pretty localized change.

However, does this really solve Kris' problem?  JDBC generally likes to
think that it works with old Postgres versions; will a fix that only
works in >= 7.5 be good enough for them?
        regards, tom lane


Re: execute command tag including affected rows count

From
Kris Jurka
Date:

On Sun, 21 Mar 2004, Tom Lane wrote:

> > On 21-Mar-04, at 11:39 AM, Kris Jurka wrote:
> >> Would it be possible to have the command completion tag for EXECUTE 
> >> return
> >> the affected row count?
> 
> However, does this really solve Kris' problem?  JDBC generally likes to
> think that it works with old Postgres versions; will a fix that only
> works in >= 7.5 be good enough for them?
> 

I oversimplified the description of the current patch I'm working on,
server side prepared statement support has been in the driver since the
7.3 days.  So this problem already exists and has simply been unnoticed.  
With the current code it is difficult to enable server prepared statements
and requires writing pg specific code outside of the standard JDBC API.  
The patch I'm reviewing makes it simple to turn on server prepared 
statements globally and brought this bug to my attention.  I would say 
"better late than never."

Kris Jurka


Re: execute command tag including affected rows count

From
Bruce Momjian
Date:
Neil Conway wrote:
> On 21-Mar-04, at 11:39 AM, Kris Jurka wrote:
> > Would it be possible to have the command completion tag for EXECUTE 
> > return
> > the affected row count?
> 
> Yes, this has been suggested before -- for example:
> 
> http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg26787.html
> 
> I agree it would be a good idea, although I can't recall what the 
> conclusion of the previous discussions was -- did anyone raise any 
> critical objections to this?

Should this be a TODO?

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073