Re: nextval() clarification

From: Ennio-Sr <nasr(dot)laili(at)tin(dot)it>
To: Greg Donald <destiney(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: nextval() clarification
Date: 2004-09-13 19:54:11
Message-ID: 20040913195410.GA10247@deby.ei.hnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

* Greg Donald <destiney(at)gmail(dot)com> [130904, 13:59]:
> Long time MySQL user, six weeks into Postgres here.
>
> I'm converting a PHP script that uses MySQL to use Postgres instead.
> To substitue the missing MySQL functionaility with mysql_insert_id()
> and auto_increment I am using code like this:
>
> $sql = "SELECT nextval('companies_company_id_seq'::text)";
>
> And then I do my insert with that value.
> [ cut ]

I think you should put <nextval(....)> directly into the INSERT
instruction, so that it advances only once per added record.
Have a look at Documentation PostgreSQL 7.4, Ch 9.11, table 9.34.
HTH
Regards, Ennio

--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
[Why to use Win$ozz (I say) if ... "even a fool can do that. )=(
Do something you aren't good at!" (used to say Henry Miller) ]

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Aarni Ruuhimäki 2004-09-13 20:05:13 Re: nextval() clarification
Previous Message Aarni Ruuhimäki 2004-09-13 19:47:16 Re: nextval() clarification