Обсуждение: Get the last sql error
Dear all,
I'm trying to find a way to get the last
sql error which happened on a database.
Found that the last command could be retrieved with
"select current_query(); ". Is there a simple way to get
the last error code (something like select @@error in MS Sql Server)?
Any hint is appreciated. Thank you in advance.
Best regards
Erik Ande
G. Muth Partners GmbH
Borsigstrasse 32
D-65205 Wiesbaden
HRB 10196 Amtsgericht Wiesbaden
Geschäftsführer: Klaus Gockel
Tel +49 (0)6122 5981-64
Fax +49 (0)6122 5981-50
Mobil +49 (0)171 3818912
Mail: Erik.Ande@MuthPartners.de
Internet: http://www.MuthPartners.de
1. definition: "Returns an error number if the previous statement encountered an error." by http://msdn.microsoft.com/en-us/library/ms188790.aspx
2. last (? - maybe first) error in current transaction
3. You use plpgsql
You can use GET STACKED DIAGNOSTICS (http://www.postgresql.org/docs/9.2/static/plpgsql-control-structures.html#PLPGSQL-EXCEPTION-DIAGNOSTICS). I think full BEGIN...EXCEPTION...END will do the work for you.
Regards,
Bartek
Bartek