I tried the below query to import data
COPY table_name(id, name, create_uid, create_date, write_uid, write_date)
FROM '/path/filename.csv'
DELIMITER ',' CSV HEADER ENCODING 'UTF8' QUOTE '"' ESCAPE '''';
The name field data type is JSONB. I tried the below formats in my CSV file.
These 2 formats both produced the same error:
"{"en_US": "Test record"}" or {"en_US": "Test record"}
Error: ERROR: invalid input syntax for type json
DETAIL: Token "en_US" is invalid.
and this format produced a different error:
'{"en_US": "Test record"}'
ERROR: invalid input syntax for type json
DETAIL: Token "'" is invalid.
How can I fix the above errors?
Postgres uses " as escaping characters. Since importing from CSV file, postgres will escape the quotes.
Try something like,
"{""en_us"": ""Test record""}"
or
"{\"en_us\": \"Test record\"}"
How to import a file in this format -
"ID" "NBR"
"101931126593" "3"
I have tried the following -
1) \copy last from 'test1.txt' with CSV DELIMITER E'\t';
2) \copy last from 'test1.txt' DELIMITER E'\t' CSV HEADER;
3) \copy last from 'test1.txt';
Below is the error I get -
ERROR: missing data for column "nbr"
I have a CSV file -- > named -- myWidechar1.csv and the data in it is as follows:
1~"ϴAnthony"~"Grosse"~"1980-02-23"~"65000.00"
2~"❤Alica"~"Fatnowna"~"1963-11-14"~"45000.00"
3~"☎Stella"~"Rossenhain"~"1992-03-02"~"120000.00"
Copy Command in PostgreSQL is as follows:
Copy dbo.myWidechar From 'D:\temp\myWidechar1.csv' DELIMITER '~' null as 'null' encoding 'windows-1251' CSV; select 1;
But problem is I am getting the below error while importing data into PostgreSQL:
ERROR: invalid byte sequence for encoding "WIN1251": 0x00 CONTEXT:
COPY mywidechar, line 3 SQL state: 22021
I need the data to remain same even in PostgreSQL as I am migrating data from SQL Server 2000 instance.
Can some one please help me in resolving this issue ?
I'm importing data from csv file into postgres db using pgadmin 4
Everything is ok but I get an issue when I try to import a file which contain some data like this
“‘t Zand, Vlotbrug”
“Dussen, `t Middeltje”
as you can see, the data contains
`
and
'
I also tried to import the file with utf-8 encoding but could not.
Anyone knows how to solve this issue?
Updated
Structure:
stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,stop_timezone,wheelchair_boarding,platform_code,zone_id
Data:
stoparea:123953,,"De Zande, 'Koelucht'",52.5184475,5.956368,1,,,0,,
Error:
ERROR: unterminated CSV quoted field
CONTEXT: COPY stops, line 69400: "stoparea:123953,,"De Zande, 'Koelucht'",52.5184475,5.956368,1,,,0,,
stoparea:120536,,"Poortvliet, Zu..."
Updated 2
Command:
"/Applications/pgAdmin 4.app/Contents/SharedSupport/psql" --command "
"\copy transit.stops (stop_id, stop_code, stop_name, stop_lat,
stop_lon, location_type, parent_station, stop_timezone,
wheelchair_boarding, platform_code, zone_id) FROM
'/Users/tvtan/Desktop/gtfs-nl/stops.txt' DELIMITER ',' CSV HEADER
QUOTE '\"' ESCAPE '''';""
UI:
From the command line it looks like you have defined the ESCAPE character as a single quote. The single quote appears in your data but is not escaped.
The default ESCAPE character is the same as the QUOTE character.
More information here
Hi I did this command on my original DB :
\COPY (SELECT * FROM cms_title WHERE title = 'Migration-test') TO '/Users/JayCee/cms_title_dump.csv' WITH CSV HEADER DELIMITER ';' NULL AS '';
It worked fine.
But when I try to copy it to an other DB I have this :
\COPY cms_title FROM 'cms_title_dump.csv' DELIMITER ';' CSV;
ERROR: invalid input syntax for integer: "id"
CONTEXT: COPY cms_title, line 1, column id: "id"
I don't understand, here is what I have when I do a cat -e on my file :
id;language;title;page_title;menu_title;meta_description;slug;path;has_url_overwrite;redirect;creation_date;published;publisher_is_draft;publisher_state;page_id;publisher_public_id$
217;en;Migration-test;"";"";"";migration-test;migration-test;f;"";2015-11-24 13:01:52.184969+00;t;t;0;99;218$
wow I am so lost even after reading tons of subject.. But contrary to those, I don't see any mistake here!
Your \COPY command generates a header line which is being read by the import command as data.
Either you do not generate the header line or tell the import command to not read the first line.
To avoid the header line generation omit the HEADER option.
To ignore the header line insert the HEADER option in the import command.