Re: Creating Primary Key after CREATE TABLE: Is Sequence created?

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Creating Primary Key after CREATE TABLE: Is Sequence created?
Date: 2013-09-27 18:59:56
Message-ID: 1380308396845-5772636.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Elliot 2013-09-27 19:04:14 Re: Creating Primary Key after CREATE TABLE: Is Sequence created?
Previous Message Sergey Konoplev 2013-09-27 18:37:13 Re: ENUM drop label workaround