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 8154055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:13:09+00:00 2026-06-06T16:13:09+00:00

I am importing data from a CSV file into a postgreSQL table. The table

  • 0

I am importing data from a CSV file into a postgreSQL table.

The table looks like this:

CREATE TABLE foo_stats (
                        td                      DATE NOT NULL,
                        ins_id                  INTEGER CHECK (ins_id > 0) NOT NULL,
                        df_id                   INTEGER CHECK (df_id > 0) NOT NULL,
                        pc                      REAL NOT NULL DEFAULT 0.0,
                        ph                      REAL DEFAULT 0.0 NOT NULL,
                        pl                      REAL DEFAULT 0.0 NOT NULL,
                        av                      REAL DEFAULT 0.0 NOT NULL,
                        cv                      BIGINT DEFAULT 0 NOT NULL,
                        avi                     REAL DEFAULT 0.0 NOT NULL,
                        cmi                     BIGINT DEFAULT 0 NOT NULL,
                        vwp                     REAL CHECK (vwp >= 0) NOT NULL,
                        atr                     REAL NOT NULL DEFAULT -99999,
                        pv                      REAL NOT NULL DEFAULT -99999,
                        pr                      REAL NOT NULL DEFAULT -99999,

                        PRIMARY KEY                     (ins_id, df_id, td)
                        );

BEFORE the bulk copy, I drop the primary key using ALTER TABLE DROP CONSTRAINT PRIMARY KEY

Here is a trace of the CL when I invoke the COPY command at the psql CLI:

mydb=# COPY foo_stats FROM '/path/to/data/foo_stats.csv' WITH CSV;
ERROR:  invalid input syntax for integer: "1990-01-02"
CONTEXT:  COPY foo_stats, line 1, column id: "1990-01-02"
mydb=# 

Here is what the first few lines of the input CSV file looks like:

"1990-01-02",388,3,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999
"1990-01-02",388,4,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999
"1990-01-02",388,1,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999
"1990-01-02",388,7,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999
"1990-01-02",388,6,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999

The data columns in the input file are in the same order as in the table schema. Can anyone explain why I am getting the error message?

PS: I am using PostgreSQL 8.4 on Ubuntu 10.0.4 LTS

  • 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-06T16:13:11+00:00Added an answer on June 6, 2026 at 4:13 pm

    Cutting and pasting your table definition and sample data here shows everything working.

    So – either your table definition or your file are not as you think they are. If your table columns are in a different order, you can specify columns in the COPY command.

    If the file is different, it’s presumably something not visible to the naked eye, or you would have spotted it before asking. I don’t suppose this file has come from a Windows machine by any chance?

    Three things to check for:

    1. Unnecessary byte-order-mark (BOM) at the start of the file
    2. Line-endings of \r\n rather than \n
    3. Any other control-codes

    Try cutting + pasting your sample data and see if that imports. If so, try opening your real file in a text editor and re-saving it. If that fixes things, get a hex editor and take a look at the actual bytes in your sample file.

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

Sidebar

Related Questions

I have some questions about importing data from Excel/CSV File into SQL Server. Let
I am importing data into a sql table from a csv using an xml
I am importing data from csv file, sometimes there are column headers and some
I am importing data from a CSV file. One of the fields has an
When importing a CSV file into Excel, it only strips the double-quotes from the
I'm importing data from a CSV that contains approx 350 columns. This CSV import
I'm importing data from a CSV file that comes from excel, but i can't
I have a web form used for importing data from a CSV file. It
I am using PHP to expose vehicle GPS data from a CSV file. This
I am importing data from a CSV file using fgetcsv(), which yields an array

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.