Adding info to pgsql table from txt/cvs

Discussion in 'Linux & BSD' started by Dark Atheist, Mar 23, 2008.

  1. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void
    i have a txt file with a few companies names in and rather than put them in one by one (there are about 100+) i have been trying to use the compy command

    COPY comanies FROM /usr/home/carpo/comp.txt

    but it always comes back with a syntax error

    ERROR: invalid input syntax for integer: "ABC Computers,"
    CONTEXT: COPY comps, line 1, column comps_id: "ABC Computers,"

    i have tried with a cvs file but some error remains
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    "ABC Computers" is not an integer, and as such can't be copied into an integer. The error is plainly telling you where it went wrong.

    You will need to make a csv file that has a unique ID for every company.
     
  3. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void
    well its not very clear on the pgsql website that's what i should do, and i used the line it gave me, and to be clear im not that great with sql - have only just started to learn it :)

    edit

    COPY comps (comp_id, comp_name) FROM '/home/carpo/comps.txt';
    1 ABC Computers
    etc etc

    i believe should do it :)
     
    Last edited: Mar 23, 2008