Re: INSERT with RETURNING clause inside SQL function

Поиск
Список
Период
Сортировка
От Diego Schulz
Тема Re: INSERT with RETURNING clause inside SQL function
Дата
Msg-id 47dcfe400811040653v41a4d165q68c094778ff92b53@mail.gmail.com
обсуждение исходный текст
Ответ на Re: INSERT with RETURNING clause inside SQL function  (Lennin Caro <lennin.caro@yahoo.com>)
Список pgsql-general
On Tue, Nov 4, 2008 at 9:57 AM, Lennin Caro <lennin.caro@yahoo.com> wrote:
>> Hi all,
>>
>> I'm re-writing some functions and migrating bussines
>> logic from a
>> client application to PostgreSQL.
>>
>> I expected something like this to work, but it doesn't:
>>
>> -- simple table
>> CREATE TABLE sometable (
>>    id SERIAL PRIMARY KEY,
>>    text1 text,
>>    text2 text
>> );
>>
>> CREATE OR REPLACE FUNCTION add_something(text, text)
>> RETURNS INTEGER AS $$
>>    INSERT INTO sometable (id, foo, bar ) VALUES (DEFAULT,
>> $1, $2 )
>> RETURNING id ;
>> $$ LANGUAGE SQL ;
>>
>>
>> Please note the use of RETURNING clause. If I put a SELECT
>> 1; after
>> the INSERT, the function works (but doesn't returns any
>> useful value
>> :)
>> I need the function to return the last insert id. And yes,
>> I'm aware
>> that the same can be achieved by selecting the greatest id
>> in the
>> SERIAL secuence, but is not as readable as RETURNING
>> syntax. And no,
>> for me it's not important that RETURNING is not
>> standard SQL.
>>
>> Does anyone knows why RETURNING doesn't works inside
>> SQL functions?
>>
>> Any advise will be very appreciated. TIA.
>>
>> diego
>>
> Hi.. what version of postgres you have?
>
>

I'm using 8.3.3.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Installation Error of postgresql-8.1.5 with perl.
Следующее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: gin creation and previous history of server