Re: SQL syntax error handling within SPI functions in C

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: SQL syntax error handling within SPI functions in C
Дата
Msg-id 20061013201732.GQ1896@svana.org
обсуждение исходный текст
Ответ на SQL syntax error handling within SPI functions in C  (Stuart Morse <stuart@optimediasolutions.ca>)
Список 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: Create Index on Date portion of timestamp
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: