error-tolerant COPY FROM

Ask a Question related to PostgreSQL / PGSQL, Design and Development.

  1. #1

    Default error-tolerant COPY FROM

    Hello everyone,

    I'm building a postgresql db which will have to get lots of data
    from "the outside" (customers, that is). The db has lots of
    constraints, and I'm sure that our customers will offer lots of
    invalid information. We receive the information in csv format. My
    first thought was to read them into the database with COPY, but
    "COPY stops operation at the first error."

    What I need is an import where all valid lines from the csv files
    are read into the db, and I also get a logfile for all invalid
    lines, stating the line number plus the pg error message so I can
    see which constraint was violated.

    I can't think of a direct, elegant solution for this, does anyone
    have any suggestions? Thanks a lot!


    ---------------------------(end of broadcast)---------------------------
    TIP 4: Don't 'kill -9' the postmaster

    Joolz Guest

  2. Similar Questions and Discussions

    1. COPY ERROR
      :confused; EVERYTIME I TRY TO OPEN A PAGE A COPY ERROR POPS UP ASKING ME IF I WANT TO RETRY OR CANCEL OR BROWSE. IT WON'T LET ME GO INTO CERTAIN...
    2. Shadow copy error! Help
      Hi I am windows 2003 ent server acting as a file server. I getting following event message: Event Type: Error Event Source: VolSnap Event...
    3. Build error: Could not copy built outputs to the Web
      I am attempting to build an asp.net project, but the build fails with the error: Could not copy built outputs to the Web. Unable to add...
    4. Error: Can not save a copy as ... document already open
      When using Photoshop 7 (and 7.0.1) on a Windows NT 4.0 SP6a PC I have a very annyoing and reproducable bug on at least two workstations. What...
    5. System.IO.File.Copy not copying and no error
      I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then throw a new exception, outputing your source/destination paths along with...
  3. #2

    Default Re: error-tolerant COPY FROM


    On Feb 4, 2005, at 21:32, Joolz wrote:
    > What I need is an import where all valid lines from the csv files
    > are read into the db, and I also get a logfile for all invalid
    > lines, stating the line number plus the pg error message so I can
    > see which constraint was violated.
    >
    > I can't think of a direct, elegant solution for this, does anyone
    > have any suggestions? Thanks a lot!
    I don't know if it's elegant or not, but my approach to this situation
    is to read the data into a temp table that does not have as strict
    constraints. Once the data is in the database, I process it further,
    moving the data that's valid into the appropriate table. Then I see
    what's left, and what further processing I need to do to "fix" the
    invalid data. Perhaps a similar strategy would work for you.

    Michael Glaesemann
    grzm myrealbox com


    ---------------------------(end of broadcast)---------------------------
    TIP 3: if posting/reading through Usenet, please send an appropriate
    subscribe-nomail command to [email]majordomo@postgresql.org[/email] so that your
    message can get through to the mailing list cleanly

    Michael Glaesemann Guest

  4. #3

    Default Re: error-tolerant COPY FROM

    Michael Glaesemann zei:
    >
    > On Feb 4, 2005, at 21:32, Joolz wrote:
    >
    >> What I need is an import where all valid lines from the csv files
    >> are read into the db, and I also get a logfile for all invalid
    >> lines, stating the line number plus the pg error message so I can
    >> see which constraint was violated.
    >>
    >> I can't think of a direct, elegant solution for this, does anyone
    >> have any suggestions? Thanks a lot!
    >
    > I don't know if it's elegant or not, but my approach to this
    > situation
    > is to read the data into a temp table that does not have as strict
    > constraints. Once the data is in the database, I process it further,
    > moving the data that's valid into the appropriate table. Then I see
    > what's left, and what further processing I need to do to "fix" the
    > invalid data. Perhaps a similar strategy would work for you.
    I'm afraid this is a bit too indirect IMHO. As I want to know the
    line number in which an error occurs, I would have to traverse the
    error-tolerant table with limit 1 offset N, and report N when an
    error occurs, hoping that the row order is identical to the line
    order in the csv file.


    ---------------------------(end of broadcast)---------------------------
    TIP 9: the planner will ignore your desire to choose an index scan if your
    joining column's datatypes do not match

    Joolz Guest

  5. #4

    Default Re: error-tolerant COPY FROM


    Csaba Nagy zei:
    > [snip]
    >> I'm afraid this is a bit too indirect IMHO. As I want to know the
    >> line number in which an error occurs, I would have to traverse the
    >> error-tolerant table with limit 1 offset N, and report N when an
    >> error occurs, hoping that the row order is identical to the line
    >> order in the csv file.
    >
    > So why don't you insert the line number too in the error tolerant
    > table
    > when you do the import ? Then you will have the line number all the
    > time. Not that I would understand what will you do with that line
    > number, once you already have all the data in the table...
    I need the line number to let the customer know which data were
    refused, and the corresponding errormessage to let him know why.


    ---------------------------(end of broadcast)---------------------------
    TIP 9: the planner will ignore your desire to choose an index scan if your
    joining column's datatypes do not match

    Joolz Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139