Re: Moving from MySQL to PGSQL....some questions (multilevel

Поиск
Список
Период
Сортировка
От Michael Chaney
Тема Re: Moving from MySQL to PGSQL....some questions (multilevel
Дата
Msg-id 20040303183725.GA23658@michaelchaney.com
обсуждение исходный текст
Ответ на Re: Moving from MySQL to PGSQL....some questions (multilevel  (Paulovič Michal <michal@paulovic.sk>)
Ответы Re: Moving from MySQL to PGSQL....some questions (multilevel  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Wed, Mar 03, 2004 at 06:45:56AM +0100, Paulovi?? Michal wrote:
> Yes I know,
>
> But how you do this at PgSQL????

You have to lock the table exclusively, get the max value for your
particular "id1", increment it, insert the row, and commit:

begin;
lock table test in exclusive mode;
insert into test values (1,(select max(id2) from test where id1=1)+1);
commit;

It's not pretty, and it'll probably slow down as the table grows.  MySQL
probably suffers the same problem.

Michael
--
Michael Darrin Chaney
mdchaney@michaelchaney.com
http://www.michaelchaney.com/

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

Предыдущее
От: "scott.marlowe"
Дата:
Сообщение: Re: Moving from MySQL to PGSQL....some questions (multilevel
Следующее
От: "Karl O. Pinc"
Дата:
Сообщение: REFERENCES error message complaint, suggestion