How to resolve an error in Importing CSV file from PostgreSQL - sql

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

Related

PostgresSQL Data importation using COPY

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...

Need to export CSV file from PSQL on Windows (psql 13) using COPY TO

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.

Getting Internal Server Error on pgSQL

Im tryingto import data from windows CSV (comma delimiter) file into pgSQL faxtest1 table, but I keep getting error saying "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."
The following is my code:
COPY faxtest1
FROM 'C:‪\Users\David\Desktop\test3.csv'
WITH DELIMITER AS ',' CSV ;
The CSV file is like:
Status,Fax ID
Fax to Email,2104
Fax to Email,2108
It is a bug of pg admin 4, hope they will fix it in the future.
In version 14, in the Import/Export data function, there are 2 columns, "Options" and "Columns." Try manually select the columns one at time, separated by a comma. See if this would by pass the error.
It worked for me.

MySQL Dump Error 1064 (42000)

I'm having a MySQL dump from Version 4.0.21. I converted it to UTF-8 to fit with the special characters such as (Ü, ü, Ä, ä, Ö, ö, ß). Now I have to import it into the latest MySQL Version 5.5.36. All data have been imported but an error occurred at the end.
ERROR 1064 (42000) at line 80769: You have an error in your SQL syntax...use near '' at line 1
The empty string and the line numbers are confusing me. Importing with phpMyAdmin results the same as command line does, with the command:
mysql -u root -p bugtracker < E:\mantisUTF.dump
The import with the original dump from Version 4.0.21 is working perfect but without the above mentioned special characters.
First Lines of the dump file:
-- MySQL dump 9.11
--
-- Host: localhost Database: Mantis
-- ------------------------------------------------------
-- Server version 4.0.21-debug
--
-- Table structure for table `mantis_bug_file_table`
--
Last Lines (80768 & 80769):
INSERT INTO mantis_user_table VALUES (57,'fullName','firstName lastName','emailAdress','dd1875c93e8f17a24ebaf9c902b7165a','2014-01-29 13:43:21','2014-03-26 13:22:47',1,0,55,14,0,0,'1b886436b0c62598ab66e40ae89f0c016dc5777ebb601a73f2a07536281113ae'
Thanks in advance.
Relax
By rechecking my question i found the problem. The problem was a missing ')' at the end of the dump file.
Last line:
INSERT INTO mantis_user_table VALUES (57,'fullName','firstName lastName','emailAdress','dd1875c93e8f17a24ebaf9c902b7165a','2014-01-29 13:43:21','2014-03-26 13:22:47',1,0,55,14,0,0,'1b886436b0c62598ab66e40ae89f0c016dc5777ebb601a73f2a07536281113ae')

Postgresql import dump with pgadmin3

i have been trying to import a Postgresql dump with my pgadmin3 interface but im running into problems. These dump was generated with pg_dump dbname > dump_file.sql
ERROR: syntax error at or near "\"
LINE 1903: \.
^
********** Error **********
ERROR: syntax error at or near "\"
SQL state: 42601
Character: 45693
the code:
--
-- Data for Name: auth_group; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY auth_group (id, name) FROM stdin;
\.
thanks
PgAdmin-III's SQL window unfortunately does not understand psql backslash commands, COPY ... FROM STDIN, etc.
You must restore with psql.
psql -f dump_file.sql