Re: How to lock and unlock table in postgresql

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: How to lock and unlock table in postgresql
Дата
Msg-id 395A6E50-370E-4403-B2A0-DED12796A317@gmail.com
обсуждение исходный текст
Ответ на How to lock and unlock table in postgresql  (Siva Palanisamy <siva_p@hcl.com>)
Ответы Re: How to lock and unlock table in postgresql  (Siva Palanisamy <siva_p@hcl.com>)
Список pgsql-general
On 17 Nov 2011, at 7:10, Siva Palanisamy wrote:

> If there is a better solution, kindly let me know.
>
>     CREATE OR REPLACE FUNCTION Fun()
>     RETURNS VOID AS '
>     DECLARE
>     Id INTEGER;
>     BEGIN
>     INSERT INTO table1 VALUES (DEFAULT, ''Sample'', DEFAULT);
>     SELECT MAX(id) INTO Id FROM table1;
>     INSERT INTO table2 VALUES(DEFAULT,Id,''sampledata'');
>     END;
>     ' LANGUAGE 'plpgsql';
>
> Regards,
> Siva.

As John says, you're re-inventing the wheel that sequences solve. You could also get the id using INSERT .. RETURNING.

You have another problem on your hands though. You have a naming conflict between your variable name and a column name
inthat second query: id and Id are the same. 

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


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

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: How to lock and unlock table in postgresql
Следующее
От: Raghavendra
Дата:
Сообщение: Re: Foreign Tables