Re: adding a new data to existing psql table from comma del file

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: sloftus <sgloftus(at)lbgeographic(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: adding a new data to existing psql table from comma del file
Date: 2004-12-31 05:38:08
Message-ID: 20041231053808.GA95884@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jason Dixon 2005-01-01 16:04:16 Grant on multiple objects
Previous Message Michael Fuhr 2004-12-31 04:06:36 Re: ERROR: relation "managers" does not exist