| От | Tom Lane |
|---|---|
| Тема | Re: PostgreSQL problem with functions |
| Дата | |
| Msg-id | 8497.992353620@sss.pgh.pa.us обсуждение |
| Ответ на | PostgreSQL problem with functions ("Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu>) |
| Список | pgsql-novice |
LOCK TABLE IN EXCLUSIVE MODE is hardly the way to program a function
that you want to be able to invoke concurrently from multiple backends.
Moreover, "SELECT max()" is going to be slow --- and you're doing it
while holding the exclusive lock! Concurrent performance is gonna be
awful.
A much better solution to your problem is to use a sequence object to
generate the ID values. For example:
new_id := nextval(''seq_name'');
INSERT INTO admin_session VALUES (new_id, a_ss, ''now'', ...);
return new_id;
BTW, this could be the complete body of your function. The "SELECT FROM
a_user" check would be better handled by defining a foreign-key
constraint on the a_id column.
regards, tom lane
В списке pgsql-novice по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера