Unix Technical Forum

pg_dump serial UNIQUE NOT NULL PRIMARY KEY

This is a discussion on pg_dump serial UNIQUE NOT NULL PRIMARY KEY within the Pgsql General forums, part of the PostgreSQL category; --> Hello, I'm a fairly new user of PostgreSQL 8.0.2 and I'm creating a table like this: CREATE TABLE cases ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 08:40 PM
Michael Hipp
 
Posts: n/a
Default pg_dump serial UNIQUE NOT NULL PRIMARY KEY

Hello, I'm a fairly new user of PostgreSQL 8.0.2 and I'm creating a table like
this:

CREATE TABLE cases (
id serial PRIMARY KEY,

Works fine, but when I pg_dump the database, what shows up in the dump is:

CREATE TABLE cases (
id serial NOT NULL,

The documentation seems to say that 'serial NOT NULL' is not at all the same
as 'serial PRIMARY KEY':

( http://www.postgresql.org/docs/8.0/s...ATATYPE-SERIAL )

"Note: Prior to PostgreSQL 7.3, serial implied UNIQUE. This is no longer
automatic. If you wish a serial column to be in a unique constraint or a
primary key, it must now be specified, same as with any other data type."

Any help appreciated,
Michael Hipp

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 08:40 PM
Michael Fuhr
 
Posts: n/a
Default Re: pg_dump serial UNIQUE NOT NULL PRIMARY KEY

On Fri, Apr 22, 2005 at 04:44:05PM -0500, Michael Hipp wrote:
>
> Hello, I'm a fairly new user of PostgreSQL 8.0.2 and I'm creating a table
> like this:
>
> CREATE TABLE cases (
> id serial PRIMARY KEY,
>
> Works fine, but when I pg_dump the database, what shows up in the dump is:
>
> CREATE TABLE cases (
> id serial NOT NULL,
>
> The documentation seems to say that 'serial NOT NULL' is not at all the
> same as 'serial PRIMARY KEY':


Later in the dump file you should see something like this:

ALTER TABLE ONLY cases
ADD CONSTRAINT cases_pkey PRIMARY KEY (id);

Presumably that's because adding the primary key constraint after
populating the table is more efficient than populating the table
with the constraint (and the associated index) in place.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 08:40 PM
Tom Lane
 
Posts: n/a
Default Re: pg_dump serial UNIQUE NOT NULL PRIMARY KEY

Michael Hipp <Michael@Hipp.com> writes:
> Hello, I'm a fairly new user of PostgreSQL 8.0.2 and I'm creating a table like
> this:


> CREATE TABLE cases (
> id serial PRIMARY KEY,


> Works fine, but when I pg_dump the database, what shows up in the dump is:


> CREATE TABLE cases (
> id serial NOT NULL,


pg_dump prefers to add the PRIMARY KEY via an ALTER TABLE, after it's
got done loading data into the table. This is basically a speed hack
(see the manual's advice about bulk data loading).

If you don't see an appropriate ALTER down near the end of the dump,
then you've got grounds for complaint ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:03 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com