Re: Converting uuid primary key column to serial int - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Converting uuid primary key column to serial int
Date
Msg-id 201106081654.50842.adrian.klaver@gmail.com
Whole thread Raw
In response to Re: Converting uuid primary key column to serial int  ("David Johnston" <polobo@yahoo.com>)
List pgsql-general

On Wednesday, June 08, 2011 1:40:35 pm David Johnston wrote:

> > -----Original Message-----

> > From: Mike Christensen [mailto:mike@kitchenpc.com]

> > Sent: Wednesday, June 08, 2011 4:26 PM

> > To: David Johnston; pgsql-general@postgresql.org

> > Subject: Re: [GENERAL] Converting uuid primary key column to serial int

> >

> >

> > I'm assuming I can still have a "Serial" column that is NOT a primary

> > key,

>

> and

>

> > it'll incremement just the same as I add rows? If that's the case, I

>

> think that's

>

> > a superior approach..

> >

> > BTW, this table is too small to worry about disk space of UUIDs and/or

> > perhaps any sort of performance benefits to using int over uuid (if there

>

> are

>

> > any)..

> >

> > Mike

>

> " CREATE TABLE t ( field serial ); " is simply short-hand for " CREATE

> TABLE t (field integer DEFAULT nextval('t_seq') ); " where the sequence

> "t_seq" is automatically created and linked to the table.

>

Actually per the docs and for completeness sake:

http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html#DATATYPE-SERIAL

CREATE SEQUENCE tablename_colname_seq;

CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
So the NOT NULL is already included.

>

> David J.

--

Adrian Klaver

adrian.klaver@gmail.com

pgsql-general by date:

Previous
From: Mike Christensen
Date:
Subject: Re: Converting uuid primary key column to serial int
Next
From: Craig Ringer
Date:
Subject: Re: Best Practices - Securing an Enterprise application using JBOSS & Postgres