Solved! Re: Problems with GET DIAGNOSTICS SELECT PROCESSED INTO result;

Поиск
Список
Период
Сортировка
От Dr. Evil
Тема Solved! Re: Problems with GET DIAGNOSTICS SELECT PROCESSED INTO result;
Дата
Msg-id 20010906211036.23088.qmail@sidereal.kz
обсуждение исходный текст
Ответ на Problems with GET DIAGNOSTICS SELECT PROCESSED INTO result;  ("Dr. Evil" <drevil@sidereal.kz>)
Список pgsql-general
I got the syntax for that by searching around on mailing list
archives.  I should have searched the PG documentation, because this
definitely works:

DROP TABLE junk;
CREATE TABLE junk (something INT4);

DROP FUNCTION testfunction(INT4);
CREATE FUNCTION testfunction(INT4) RETURNS INT4 AS '
DECLARE
    result INT4;
BEGIN
    INSERT INTO junk (something) VALUES ($1);
    GET DIAGNOSTICS result = ROW_COUNT;
    RETURN result;
END;
' LANGUAGE 'plpgsql';

So I guess the syntax has changed a little bit between beta and
released versions.

This is a very useful (essential) feature, because let's say that you
have a table with some constraints or integrity checks, and you try to
insert something which for whatever reason may violate those
constraints.  The script needs to have some way of knowing that the
insert failed.  So this is a great feature to have.

Thanks Postgres!

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

Предыдущее
От: Daniel Åkerud
Дата:
Сообщение: Re: SERIAL, too low a value
Следующее
От: jd@commandprompt.com (Joshua Drake)
Дата:
Сообщение: Re: Great Bridge ceases operations