2

I was able to import two tables using this method but it's not working for the third table. When I run the query it doesn't show error just shows blank.

Postgresql COPY CSV ERROR: extra data after last expected column

I got the format from above.

CREATE TABLE GrossNewHomeSales
        (ID varchar not null primary key, nhs_transaction_id varchar not null unique,   
         nhs_week_ending varchar,   nhs_sale_date varchar,  nhs_owner_name varchar,
         nhs_owner_age varchar, nhs_address varchar,    nhs_sf varchar, nhs_realtor_sale varchar,   
         nhs_realtor_name varchar,  nhs_realtor_office varchar, nhs_prev_zip varchar, nhs_employment varchar
);

COPY GrossNewHomeSales (ID, nhs_transaction_id, nhs_week_ending,    nhs_sale_date,
                    nhs_owner_name, nhs_owner_age,  nhs_address,    nhs_sf,
                    nhs_realtor_sale,   nhs_realtor_name,   nhs_realtor_office, nhs_prev_zip,
                    nhs_employment
)                    
FROM
'C:\Program Files\PostgreSQL\9.6\data\GrossNewHomeSales.csv'
WITH CSV HEADER DELIMITER ',';
0

1 Answer 1

2

PostgreSQL is probably expecting UTF8 encoding for the file, but since you created the file on Windows, it is not. You have 2 choices:

  1. Save the file with UTF8 encoding.

    Should be as simple as opening the CSV in notepad (or equivalent) and saving with the proper (UTF8) encoding.

  2. Specify the proper encoding in the COPY command.

    Example: ENCODING 'WIN1257'

Here is a list of what PostgreSQL supports: https://www.postgresql.org/docs/current/static/multibyte.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.