Re: Moving from MySQL to PGSQL....some questions (multilevel - Mailing list pgsql-general

From Michael Chaney
Subject Re: Moving from MySQL to PGSQL....some questions (multilevel
Date
Msg-id 20040303183725.GA23658@michaelchaney.com
Whole thread Raw
In response to Re: Moving from MySQL to PGSQL....some questions (multilevel  (Paulovič Michal <michal@paulovic.sk>)
Responses Re: Moving from MySQL to PGSQL....some questions (multilevel
List 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 by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: Moving from MySQL to PGSQL....some questions (multilevel
Next
From: "Karl O. Pinc"
Date:
Subject: REFERENCES error message complaint, suggestion