From: | "dario(dot)ber(at)libero(dot)it" <dario(dot)ber(at)libero(dot)it> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Catch exception from plpy |
Date: | 2010-04-24 12:48:33 |
Message-ID: | 32426425.1630381272113313707.JavaMail.defaultUser@defaultHost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
Could someone show me how to catch exceptions generated by plpy.execute()?
>From the documentation and other posts I understand that you need to call plpy.
error() but I still cannot figure out how to use it.
For example, say I need a function that creates table foo if it doesn't
exists, otherwise returns the rows in foo. Initially I thought the following
shouldl work... but it doesn't!
--
create or replace function test_tryex() returns void AS $$
try:
plpy.execute('create table tmp_foo (v1 int);')
except:
plpy.execute('select * from tmp_foo;')
$$
language plpythonu;
--
-- If tmp_foo already exists I get:
select test_tryex();
********** Error **********
ERROR: relation "tmp_foo" already exists
SQL state: 42P07
Context: SQL statement "create table tmp_foo (v1 int);"
Many thanks in advance
Dario
From | Date | Subject | |
---|---|---|---|
Next Message | Martin Gainty | 2010-04-24 13:42:20 | Re: Catch exception from plpy |
Previous Message | dipti shah | 2010-04-24 12:01:19 | Syntax error in spi_prepare usage |