Frequently Asked Questions (FAQ) for PostgreSQL
- Last updated: Sat Nov 15 23:41:03 EST 2003
+ Last updated: Wed Nov 19 11:50:04 EST 2003
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
4.15.1) How do I create a serial/auto-incrementing field?
- PostgreSQL supports a SERIAL data type. It auto-creates a sequence and
- index on the column. For example, this:
+ PostgreSQL supports a SERIAL data type. It auto-creates a sequence.
+ For example, this:
CREATE TABLE person (
id SERIAL,
name TEXT
id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
name TEXT
);
- CREATE UNIQUE INDEX person_id_key ON person ( id );
See the create_sequence manual page for more information about
sequences. You can also use each row's OID field as a unique value.
alink="#0000ff">
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
- <P>Last updated: Sat Nov 15 23:41:03 EST 2003</P>
+ <P>Last updated: Wed Nov 19 11:50:04 EST 2003</P>
<P>Current maintainer: Bruce Momjian (<A href=
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
serial/auto-incrementing field?</H4>
<P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It
- auto-creates a sequence and index on the column. For example,
+ auto-creates a sequence. For example,
this:</P>
<PRE>
CREATE TABLE person (
id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
name TEXT
);
- CREATE UNIQUE INDEX person_id_key ON person ( id );
</PRE>
See the <I>create_sequence</I> manual page for more information