From: | Marco Colombo <marco(at)esi(dot)it> |
---|---|
To: | Zavier Sheran <zsheran(at)yahoo(dot)com> |
Cc: | <pgsql-php(at)postgresql(dot)org> |
Subject: | Re: Nextval |
Date: | 2001-10-12 11:56:18 |
Message-ID: | Pine.LNX.4.33.0110121350120.28896-100000@Megathlon.ESI |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
On Thu, 11 Oct 2001, Zavier Sheran wrote:
> I try to do the following:
>
> Fetch a SERIAL field (ie. record_id) and get the
> highest value currently stored (ie. 1000), increment
> the value by 1 and store a record that will have the
> same value (1001) in record_id. So there must be a way
> with concurrency control.
>
> I went through the manuals and found the solution with
> NEXTVAL('serial'), but you have to create a sequence
> for that, and I don't know if it is the right way to
> do for what I want.
>
> It is my first PHP project involving a Database, so
> it's a newbie question. Have mercy...
>
> Thanks
>
marco=# create table test_serial ( id serial );
NOTICE: CREATE TABLE will create implicit sequence 'test_serial_id_seq' for SERIAL column 'test_serial.id'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_serial_id_key' for table 'test_serial'
The serial type automagically creates both a sequence and an index:
the sequence is named <table>_<column>_seq and the index
<table>_<column>_key.
You can use nextval() on the sequence if you like, as in:
insert into test_serial values ( nextval('test_serial_id_seq') );
or have the column default to that so that you don't even bother on
inserts.
.TM.
--
____/ ____/ /
/ / / Marco Colombo
___/ ___ / / Technical Manager
/ / / ESI s.r.l.
_____/ _____/ _/ Colombo(at)ESI(dot)it
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2001-10-12 16:49:44 | Re: Nextval |
Previous Message | Papp Gyozo | 2001-10-12 09:26:39 | Re: Nextval |