Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 614F9156C84B for ; Wed, 16 May 2012 15:50:03 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SUjIO-0004Sk-8J for pgsql-bugs@postgresql.org; Wed, 16 May 2012 18:50:02 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SUjIA-0006BV-PB for pgsql-bugs@postgresql.org; Wed, 16 May 2012 18:49:47 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SUjIA-0002FA-Bi for pgsql-bugs@postgresql.org; Wed, 16 May 2012 18:49:46 +0000 Date: Wed, 16 May 2012 18:49:46 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6646: PL/Python spiexceptions raised inside Python do not include sqlstate in external code To: pgsql-bugs@postgresql.org From: steve@empiricalthought.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/102 X-Sequence-Number: 33073 The following bug has been logged on the website: Bug reference: 6646 Logged by: Steven Huwig Email address: steve@empiricalthought.com PostgreSQL version: 9.1.3 Operating system: Linux Description: = I am trying to raise standard SQL errors from inside PL/Python code. However, they do not work as expected. They always have sqlstate =3D XX000 instead of the appropriate sqlstate value. create function python_exception_bug() returns void as $$ raise plpy.spiexceptions.InvalidParameterValue() $$ language 'plpython3u'; create function python_exception_sql() returns text as $$ begin select python_exception_bug(); return 'cannot happen'; exception when invalid_parameter_value then return 'expected behavior'; when others then return 'this is a bug'; end $$ language 'plpgsql';