Skip site navigation (1) Skip section navigation (2)

SQL scripts - sequences

From: "Adam Lang" <aalang(at)rutgersinsurance(dot)com>
To: "PGSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: SQL scripts - sequences
Date: 2000-08-29 15:36:13
Message-ID: 00fb01c011ce$dd1bdda0$330a0a0a@Adam (view raw or flat)
Thread:
Lists: pgsql-general
I'm building a database and making my table creates in a text file so that,
if I want to recreate my database, I can just rerun the scripts.

At the top of the script are the statements to drop the tables.  Next is the
area which creates the tables.

The problem I am encountering is with having a primary key labeled as
serial.  Do I have to drop the sequence also to be able to recreate the
table?  Omitting the sequence drop did not seem to allow the creation of the
table with a serial, but when I added a drop sequence, the table creates
fine in the script.  Am I assuming correctly?

If that is correct, what if I go a step farther and have data dumped from
the table before it is dropped.  Won't my sequence be screwed up if I drop
it and then reimport the data?  Would the sequence technically be back at 1
and if I have 100 records, will it try to insert duplicate data?

If that is true, what would be the solution?  Create the sequence manually,
don't drop the sequence in the script, and have the create table script not
as a SERIAL, but have it set to a default value of the sequence?

Adam Lang
Systems Engineer
Rutgers Casualty Insurance Company


Responses

pgsql-general by date

Next:From: Tom LaneDate: 2000-08-29 15:43:16
Subject: Re: 7.1 Release Date
Previous:From: Adam LangDate: 2000-08-29 15:24:34
Subject: Re: Ignore when using COPY FROM

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group