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

From: Michael Chaney <mdchaney(at)michaelchaney(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Moving from MySQL to PGSQL....some questions (multilevel
Date: 2004-03-03 18:37:25
Message-ID: 20040303183725.GA23658@michaelchaney.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)michaelchaney(dot)com
http://www.michaelchaney.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2004-03-03 18:43:16 Re: Moving from MySQL to PGSQL....some questions (multilevel
Previous Message Paulovič Michal 2004-03-03 18:36:02 Re: Moving from MySQL to PGSQL....some questions (multilevel