execute command tag including affected rows count

Started by Kris Jurkaalmost 22 years ago5 messages
#1Kris Jurka
books@ejurka.com

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

#2Neil Conway
neilc@samurai.com
In reply to: Kris Jurka (#1)
Re: execute command tag including affected rows count

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#2)
Re: execute command tag including affected rows count

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

#4Kris Jurka
books@ejurka.com
In reply to: Tom Lane (#3)
Re: execute command tag including affected rows count

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

#5Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Neil Conway (#2)
Re: execute command tag including affected rows count

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, Pennsylvania 19073