pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Retrieving multiple error messages via libpq
2+ messages / 2 participants
[nested] [flat]

* Retrieving multiple error messages via libpq
@ 2007-11-26 02:48 Jeffrey Brendecke <yakhki@yahoo.de>
  2007-11-26 02:55 ` Re: Retrieving multiple error messages via libpq Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Jeffrey Brendecke @ 2007-11-26 02:48 UTC (permalink / raw)
  To: pgsql-interfaces

I am working on a client that interfaces to the database via libpq, but cannot see how to get all error messages in some cases.

For testing purposes, I created the following table:

CREATE TABLE IdOnly
(
    id          INTEGER     PRIMARY KEY
);

When I submit the following SQL statement for execution via the psql client:

'BEGIN TRANSACTION; INSERT INTO IdOnly (id) VALUES (40); INSERT INTO IdOnly (id) VALUES (21); INSERT INTO IdOnly (id) VALUES (42); COMMIT TRANSACTION;'

I get the following error messages (this failure is expected):

ERROR:  duplicate key violates unique constraint "idonly_pkey"
ERROR:  current transaction is aborted, commands ignored until end of transaction block

However, when retreiving the error message via PQresultErrorMessage(), I get:
ERROR:  duplicate key violates unique constraint "idonly_pkey"

and through PQresultErrorField(, PGresult*, PG_DIAG_MESSAGE_PRIMARY ), I get only:
duplicate key violates unique constraint "idonly_pkey"

Calling PQresultErrorField( PGresult*,  PG_DIAG_MESSAGE_DETAIL )" returns no additional information.

How is the additional error message retrieved?








      Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: 
http://de.yahoo.com/set



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

* Re: Retrieving multiple error messages via libpq
  2007-11-26 02:48 Retrieving multiple error messages via libpq Jeffrey Brendecke <yakhki@yahoo.de>
@ 2007-11-26 02:55 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2007-11-26 02:55 UTC (permalink / raw)
  To: Jeffrey Brendecke <yakhki@yahoo.de>; +Cc: pgsql-interfaces

Jeffrey Brendecke <yakhki@yahoo.de> writes:
> When I submit the following SQL statement for execution via the psql client:

> 'BEGIN TRANSACTION; INSERT INTO IdOnly (id) VALUES (40); INSERT INTO IdOnly (id) VALUES (21); INSERT INTO IdOnly (id) VALUES (42); COMMIT TRANSACTION;'

> I get the following error messages (this failure is expected):

> ERROR:  duplicate key violates unique constraint "idonly_pkey"
> ERROR:  current transaction is aborted, commands ignored until end of transaction block

> However, when retreiving the error message via PQresultErrorMessage(), I get:
> ERROR:  duplicate key violates unique constraint "idonly_pkey"

> How is the additional error message retrieved?

It isn't, because there isn't any additional message.  When you submit
multiple commands in a single PQexec string (as I suspect you did),
the backend abandons processing the string as soon as there's one error.
psql, however, chops up its input at semicolons and submits each command
as a separate PQexec.

			regards, tom lane



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


end of thread, other threads:[~2007-11-26 02:55 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-11-26 02:48 Retrieving multiple error messages via libpq Jeffrey Brendecke <yakhki@yahoo.de>
2007-11-26 02:55 ` Tom Lane <tgl@sss.pgh.pa.us>

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