Re: Creating Primary Key after CREATE TABLE: Is Sequence created? - Mailing list pgsql-general

From David Johnston
Subject Re: Creating Primary Key after CREATE TABLE: Is Sequence created?
Date
Msg-id 1380308396845-5772636.post@n5.nabble.com
Whole thread Raw
In response to Creating Primary Key after CREATE TABLE: Is Sequence created?  (mdr <monosij.forums@gmail.com>)
List pgsql-general
mdr wrote
> I had a question on creating PK with alter table, after table is created.
>
> I understand I create a PK id during create table by stating id as
> follows:
> id serial primary key
>
> It implicitly creates index and the sequence testing_id_seq to be
> associated with the id field.
> I can list the sequence with \ds.

"PRIMARY KEY" implicitly creates an index
"serial" (i.e., the column type) implicitly creates a sequence (of type
integer; bigserial creates a biginteger sequence)

psuedo-sql:

CREATE TABLE a (id serial);  ALTER TABLE a ADD CONSTRAINT PRIMARY KEY (id);

The first creates the serial; the second creates the index and unique
constraint.  Should be equivalent to:

CREATE TABLE a (id serial PRIMARY KEY);

David J.








--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Creating-Primary-Key-after-CREATE-TABLE-Is-Sequence-created-tp5772633p5772636.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Sergey Konoplev
Date:
Subject: Re: ENUM drop label workaround
Next
From: Elliot
Date:
Subject: Re: Creating Primary Key after CREATE TABLE: Is Sequence created?