Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    135

    Unanswered: Copy a file to a table

    Hi,

    How to copy a text file to a table. Do any script or function is there...............

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by bklr
    How to copy a text file to a table. Do any script or function is there...............
    Check out the COPY command if the file is on the server
    http://www.postgresql.org/docs/current/static/sql-copy.html

    or use psql's \copy command if the file is not on the server:
    http://www.postgresql.org/docs/current/static/app-psql.html

  3. #3
    Join Date
    Dec 2008
    Posts
    135
    copy fr000011 from '/var/www/html/kbysani/fr000011.csv' using DELIMITERS ' ';

    it is giving the error as
    extra data after last expected column
    CONTEXT: COPY fr000011, line 1: "20348 1 1.00 38297423478923748923748923748972389472394798237489 237489237498237489237489237..."

    In statement:
    copy fr000011 from '/var/www/html/kbysani/fr000011.csv' using DELIMITERS ' ';

    data in the file as
    20348 1 1.00 38297423478923748923748923748972389472394798237489 23748923749823748923748923748923748923748972348972
    20348 1 2.00 34234892374239473238
    20349 0 1.00 PIS Title xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    20349 0 2.00 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxline 2


    columns in the table as
    pis_number character varying(10)
    revision_number character varying(3)
    text_line_number character varying(7)
    description character varying(1000)

  4. #4
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    Count the spaces in each line, that's how many columns you are going to get. Some lines have 8 columns. You need to quote it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •