Re: SQL syntax error handling within SPI functions in C

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Stuart Morse <stuart(at)optimediasolutions(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL syntax error handling within SPI functions in C
Date: 2006-10-13 20:17:32
Message-ID: 20061013201732.GQ1896@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 12, 2006 at 02:29:27PM -0700, Stuart Morse wrote:
> Hi,
>
> I've written a set of functions in C that will ultimately be called from an
> enterprise java bean. I expected that when calling SPI_exec(sql, 0) it would
> return an error code if "sql" contained a syntax error. At that point I
> would be able to return my own (more meaningful) error message based on the
> error thrown.

Find the section in the docs on exception handling. The rule is
basically: if the function gets an error it won't return. For this
reason you never have to check if palloc() returns NULL. It really
can't happen.

There are try/catch blocks you can install to catch errors. pl/pgsql
does this for example. Note it is slightly expensive, so you're usually
better off avoiding errors you know you're going to ignore anyway. An
error will abort the current transaction, no changing that, you use
subtransactions to isolate them...

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2006-10-13 20:21:36 Re:
Previous Message Andrew Sullivan 2006-10-13 20:16:07 Re: Create Index on Date portion of timestamp