Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:46:35+00:00 2026-06-11T12:46:35+00:00

I am trying to load text data into a postgresql database via COPY FROM

  • 0

I am trying to load text data into a postgresql database via COPY FROM. Data is definitely not clean CSV.

The input data isn’t always consistent: sometimes there are excess fields (separator is part of a field’s content) or there are nulls instead of 0’s in integer fields.

The result is that PostgreSQL throws an error and stops loading.

Currently I am trying to massage the data into consistency via perl.

Is there a better strategy?

Can PostgreSQL be asked to be as tolerant as mysql or sqlite in that respect?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:46:36+00:00Added an answer on June 11, 2026 at 12:46 pm

    PostgreSQL’s COPY FROM isn’t designed to handle bodgy data and is quite strict. There’s little support for tolerance of dodgy data.

    I thought there was little interest in adding any until I saw this proposed patch posted just a few days ago for possible inclusion in PostgreSQL 9.3. The patch has been resoundingly rejected, but shows that there’s some interest in the idea; read the thread.

    It’s sometimes possible to COPY FROM into a staging TEMPORARY table that has all text fields with no constraints. Then you can massage the data using SQL from there. That’ll only work if the SQL is at least well-formed and regular, though, and it doesn’t sound like yours is.

    If the data isn’t clean, you need to pre-process it with a script in a suitable scripting language.

    Have that script:

    • Connect to PostgreSQL and INSERT rows;
    • Connect to PostgreSQL and use the scripting language’s Pg APIs to COPY rows in; or
    • Write out clean CSV that you can COPY FROM

    Python’s csv module can be handy for this. You can use any language you like; perl, python, php, Java, C, whatever.

    If you were enthusiastic you could write it in PL/Perlu or PL/Pythonu, inserting the data as you read it and clean it up. I wouldn’t bother.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load some data from a text file into a vector
I am trying to load some data from a text file into mysql. I
I'm trying to use the OleDb CSV parser to load some data from a
I'm trying to load data from a text file on my server using the
I have a TableView that I am trying to load data into. From the
Trying to use 'LOAD DATA INFILE' in order to populate a database table from
I'm trying to load text of all divs that have a particular class into
Hei guys, I'm trying to load a long text from a .rtf file and
I'm trying to load a list of filenames from a text file and then
Trying to load a small .txt file into mysql but get all my data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.