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

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

From
"sloftus"
Date:
Hi,

  can somebody help me, I am trying to update a psql table in my data base.
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?

any suggestions appreciated.

sgloftus@lbgeographic




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

From
Michael Fuhr
Date:
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/