I have a CSV file with 13 columns; Id,Assigned_to,Title,Serial_number,Description, Price, Date_assigned,Purchase_date,is_assigned,is_cleared_off,is_damaged, created_at, updated_at.e terminal
I am trying to import the data to a PostgreSQL server using the terminal.
I am using the following command;
COPY assets(id,assigned_to,title,serial_number,description,price,date_assigned,purchase_date,is_assigned,is_damaged,created_at,updated_at) FROM '/home/intern2/Documents/assets_final.csv' DELIMITER ‘,’ CSV HEADER;
where /home/intern2/Documents is the file directory and the file name is assets_final.csv
I am however getting this error
ERROR: syntax error at or near "‘"
LINE 1: ...ome/intern2/Documents/assets_final.csv' DELIMITER ‘,’ CSV HE...
Related
I want to import a CSV file to PostgreSQL.
Shown below is the syntax used to import a CSV file to a created table i.e. salary_supervisor in PostgreSQL,
COPY salary_supervisor
FROM 'X:\XX\XXX\XXX\XXX\XXX\XXX\supervisor_salaries.csv' /* File path */
WITH (FORMAT CSV, HEADER);
However, it indicates an error as shown below,
ERROR: could not open file "X:\XX\XXX\XXX\XXX\XXX\XXX\supervisor_salaries.csv" for reading: Permission denied
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
SQL state: 42501
Since an error was shown above, the below syntax was used to import the CSV file to PostgreSQL,
\copy (Select * From salary_supervisor)
FROM 'X:\XX\XXX\XXX\XXX\XXX\XXX\supervisor_salaries.csv' /* File path */
WITH (FORMAT CSV, HEADER);
However, it also indicated a syntax error shown below,
ERROR: syntax error at or near "\"
LINE 1: \copy (Select * From salary_supervisor)
^
SQL state: 42601
Character: 1
I am using
\COPY
(
SELECT *
FROM person
LEFT JOIN car ON car.id=person.car_id
)
TO 'c:/Users/nick-/Downloads/results.csv'
DELIMITER ',' CSV HEADER;
and am getting the error
ERROR: syntax error at or near "TO"
LINE 6: TO 'c:/Users/nick-/Downloads/results.csv'
I've also tried COPY rather than \COPY but I get this error
ERROR: could not open file "c:/Users/nick-/Downloads/results.csv" for writing: Permission denied
HINT: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
I have tried using all of the below
c:/Users/nick-/Downloads/results.csv
c://Users//nick-//Downloads//results.csv
'c:\Users\nick-\Downloads\results.csv'
'c:\\Users\\nick-\\Downloads\\results.csv'
and none have worked.
I have 700MB txt file that I want to import into my Postgres database.
However, I keep getting the error below. "Jurs" is the last column header.
Note that error happened on a line 10014, not line 1. So I believe I have created a proper schema for a new table but I noticed, on the Line 10014, there is a "\" next to BRUNSVILLE. Is that an issue? I can't figure out what the problem is.
db1=# \COPY harris_2018 FROM 'C:\Users\testu\Downloads\harris_2018\original\
Real_acct_owner\real_acct.txt' with DELIMITER E'\t';
ERROR: missing data for column "jurs"
CONTEXT: COPY harris_2018, line 10014: "0081300000008 2018 STATE OF TEXAS PO BOX 1386
HOUSTON TX 77251-1386 N 0 ..."
Below is a txt file reader.
I am trying to import TXT file into the postgreSQL database table, but I am getting an error:
ERROR:
missing data for column "bts_name"
SQL state: 22P04
My code is:
COPY indicadores2g (
Daily,
BTS_NAME,
SITE_CODE
)
FROM 'C:\Users\Public\Documents\GEO_2G_CELL.txt'
WITH CSV HEADER DELIMITER ' ' NULL AS '' ;
I know that the problem is in the txt file. In the txt file the last two line are blank (example), and when I remove them, the SQL run without problem.enter image description here
My problem is I need to import every day. Is there any rule to put in my SQL code to run without problems?
Another way to run without problems is: Open TXT in excel and save as CSV. Can I do this automatically?
Create simple batch (for example inpfixer.bat):
#echo off
for /f "delims=" %%a in (%1) do (
echo %%a
)
Then
COPY indicadores2g (
Daily,
BTS_NAME,
SITE_CODE
)
FROM PROGRAM 'inpfixer.bat C:\Users\Public\Documents\GEO_2G_CELL.txt'
WITH CSV HEADER DELIMITER ' ' NULL AS '' ;
Surely, inpfixer.bat should be available by PATH.
Disclaimer: Tested on the Wine.
SQL*Loader-500: Unable to open file (C:\sqlloaderpra\tmp.txt)
SQL*Loader-553: file not found SQL*Loader-509: System error: The
system cannot find the file specified. SQL*Loader-2026: the load was
aborted because SQL Loader cannot continue.
Where my ctrl file is
load data
infile 'C:\sqlloaderpra\tmp.txt'
into table tmpload
append
fields terminated by ","
trailing nullcols
(
a Integer external,
b char nullif b=blanks)
Files are there but i get this error.