pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedGetting more detail in plpython error messages
3+ messages / 2 participants
[nested] [flat]
* Getting more detail in plpython error messages
@ 2022-03-07 17:46 Jeff Ross <jross@openvistas.net>
2022-03-07 18:06 ` Re: Getting more detail in plpython error messages Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Ross @ 2022-03-07 17:46 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi all,
In psql a database error will print both ERROR: and DETAIL: lines.
postgres@testdb# delete from inspection where bundle_id in (select id
from test_archive_20170401.load order by id);
ERROR: update or delete on table "inspection" violates foreign key
constraint "inspection_weather_inspection_id_inspection_id_fk" on table
"inspection_weather"
DETAIL: Key (id)=(158967) is still referenced from table
"inspection_weather".
With plpython (both u and 3u) all I see printed is the ERROR part.
try:
check = plpy.execute("delete from inspection where bundle_id in
(select id from test_archive_20170401.load order by id)")
except plpy.SPIError as e:
plpy.notice("Error!", e)
postgres@testdb# select * from test_delete();
NOTICE: ('Error!', ForeignKeyViolation('update or delete on table
"inspection" violates foreign key constraint
"inspection_weather_inspection_id_inspection_id_fk" on table
"inspection_weather"',))
Is there a way to get the DETAIL part as well?
Thanks,
Jeff
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Getting more detail in plpython error messages
2022-03-07 17:46 Getting more detail in plpython error messages Jeff Ross <jross@openvistas.net>
@ 2022-03-07 18:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-03-07 18:12 ` Re: Getting more detail in plpython error messages Jeff Ross <jross@openvistas.net>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2022-03-07 18:06 UTC (permalink / raw)
To: Jeff Ross <jross@openvistas.net>; +Cc: pgsql-general@lists.postgresql.org
Jeff Ross <jross@openvistas.net> writes:
> With plpython (both u and 3u) all I see printed is the ERROR part.
> try:
> check = plpy.execute("delete from inspection where bundle_id in
> (select id from test_archive_20170401.load order by id)")
> except plpy.SPIError as e:
> plpy.notice("Error!", e)
> postgres@testdb# select * from test_delete();
> NOTICE: ('Error!', ForeignKeyViolation('update or delete on table
> "inspection" violates foreign key constraint
> "inspection_weather_inspection_id_inspection_id_fk" on table
> "inspection_weather"',))
> Is there a way to get the DETAIL part as well?
It's not very well documented AFAICS, but a SPIError object has a
"detail" attribute, so "e.detail" should help you. It looks like
you might prefer to print "e.spidata", which seems to contain all
the available fields.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Getting more detail in plpython error messages
2022-03-07 17:46 Getting more detail in plpython error messages Jeff Ross <jross@openvistas.net>
2022-03-07 18:06 ` Re: Getting more detail in plpython error messages Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-03-07 18:12 ` Jeff Ross <jross@openvistas.net>
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Ross @ 2022-03-07 18:12 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 3/7/22 11:06 AM, Tom Lane wrote:
> Jeff Ross <jross@openvistas.net> writes:
>> Is there a way to get the DETAIL part as well?
> It's not very well documented AFAICS, but a SPIError object has a
> "detail" attribute, so "e.detail" should help you. It looks like
> you might prefer to print "e.spidata", which seems to contain all
> the available fields.
>
> regards, tom lane
>
>
Thank you, Tom! As always, that is exactly what I need.
Jeff
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2022-03-07 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 17:46 Getting more detail in plpython error messages Jeff Ross <jross@openvistas.net>
2022-03-07 18:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-03-07 18:12 ` Jeff Ross <jross@openvistas.net>
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