Re: adding a new data to existing psql table from comma del file - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: adding a new data to existing psql table from comma del file
Date
Msg-id 20041231053808.GA95884@winnie.fuhr.org
Whole thread Raw
In response to adding a new data to existing psql table from comma del file  ("sloftus" <sgloftus@lbgeographic.com>)
List pgsql-novice
On Thu, Dec 30, 2004 at 08:49:29AM -0500, sloftus wrote:

> I created the table from a
> comma deliminated file that has four col.
>
> state, city, school, autoID.
>
> the current table. RESCHOOL, has about 300 rows, and is ordered using a
> autogenerated sequence which links this table to other tables in the DB.
>
> I need to add some additional schools (about 100),from another cvs file into
> the RESCHOOL.
>
> do I use the copy comand that I used to originally used to create this file?
> Wont that overwrite my existing table, and mess up my ID's from the
> autogenerated number?

If you're not sure how something works, study the documentation and
practice on test data before trying it on "real" data.  Also, when
modifying data, you could use a transaction so you can verify changes
before committing them.  That is, issue a BEGIN statement, make the
changes, issue SELECT statements to verify that the changes are
correct, then issue COMMIT if everything looks good or ROLLBACK to
abandon the changes.

COPY inserts new records without deleting existing records.  As for
automatically-generated values (presumably a key field defined as
a SERIAL type), when you're done inserting new records you could
use ALTER SEQUENCE or setval() to adjust the sequence's value if
necessary.

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

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: ERROR: relation "managers" does not exist
Next
From: Jason Dixon
Date:
Subject: Grant on multiple objects