Cannot import .sql to PostgreSQL. Syntax error - sql

Probably a very simple error but I cannot work it out for the life of me. Basically, I am loading a .sql dump into a postgres DB using
psql testdb< C:\Users\Callum\Desktop\backup.sql
However, I get the error:
ERROR: syntax error at or near "`"
LINE 1: DROP TABLE IF EXISTS `table1`;
^
ERROR: syntax error at or near "`"
LINE 1: CREATE TABLE `table2` (
^
ERROR: syntax error at or near "`"
LINE 1: LOCK TABLES `table3` WRITE;
I have been trying to work this out for days and could not find any anwsers online.
Thanks

Are you importing from MySQL? You don't need backticks here, you can take them out.

Related

Importing database in PostgreSQL using pg_dump having ERROR: 42601: syntax error at or near "psql"

i am using PostgreSQL database for my application. Now i have to import my all databases in it.
I am using this command for importing,
psql -U postgres Employees < dbimport.pgsql
but it is not importing. I have already created the database with name Employees in my PostgreSQL.
Getting Error like,
42601: syntax error at or near "psql"
Please suggest me if i am going wrong.
if you have postgres client installed, probably you have misconfigured environmental variables ($PATH), to find the psql use instructions here: https://stackoverflow.com/a/44106963/5315974
Basically you need to usemlocate (if you have it installed) or just find...
Unrelated, but also I would avoid using mixed case in database name...
Also 42601: syntax error at or near "psql" error code means you try to run psql as SQL statement, which it is not - look into your dbimport.pgsql if you have not SQL there - maybe it is shell (or some other) script?..
The error 42601: syntax error at or near "psql" is a syntax_error from the database not from the terminal, so the value of $PATH is not wrong.
It looks like the file 'dbimport.pgsql' which you are trying to import does not contain the importable data.
Can you confirm, how this backup was taken? Or the content of file 'dbimport.pgsql'.

psql restore sql dump syntax error

I am trying to import https://www.yelp.com/dataset/documentation/sql into a PostgreSQL instance. It is having problems with accent marks/backtick. Other than doing a character replace, is there any other way to deal with this?
ERROR: syntax error at or near "PaxHeader"
LINE 1: PaxHeader/yelp_db.sql17 uid=998889796
^
ERROR: syntax error at or near "`"
LINE 1: CREATE DATABASE /*!32312 IF NOT EXISTS*/ `yelp_db` /*!40100 ...
^
ERROR: syntax error at or near "USE"
LINE 1: USE `yelp_db`;
^
ERROR: syntax error at or near "`"
LINE 1: DROP TABLE IF EXISTS `attribute`;
These are typical MySQL syntax issues that PostgreSQL conforms to the standard on and therefore doesn't support. There are a few different converters on GitHub that might help. When I had to do this last, there were tools to convert text dumps. They didn't work perfectly but they got things close enough. Reviewing the tools around today, they tend to assume you have an actual MySQL database, not just a dump file.
So it looks like the appropriate way to address this today is to load the data into MySQL and then move it to PostgreSQL. In this regard you seem to have four options that I can think of for converting the schema and data:
There are tools to convert XML dumps from MySQL and load these into PostgreSQL.
You could set up a foreign data wrapper from PostgreSQL to the MySQL db and then copy the schemas and data in.
You could manually convert the schemas, and then dump/reload the data using an ETL process via CSV.
There are tools to read a live MySQL database and insert the data into PostgreSQL.

Syntax error: Encountered "<EOF>" in derby on DROP SEQUENCE statement

Some sequences were created because of the error described here. To keep everything clean I tried to delete them with the command DROP SEQUENCE seqname;. It produces me the following message:
Error code -1, SQL state 42X01: Syntax error: Encountered "" at line 1, column 20.
Line 1, column 1
Execution finished after 0 s, 1 error(s) occurred.
I guess it is because I work on Windows machine which has different EOF marker. But how to solve the problem in SQL?
After several trials the solution is DROP SEQUENCE sequence_name RESTRICT which was found here. Adding RESTRICT to the SQL statement solves the problem

Sql error with backquotes, says there's a syntax error at or near "`"

I'm trying to load a database into Heroku from a sql file, however I get a syntax error from back quotes / backticks.
heroku pg:psql < backup.sql
Outputs this error:
syntax error at or near "`"
Why is that? Aren't backquotes valid?
I can find/replace them with something else if that would be good to try.
are you restoring from a postgresql system or another db software such mySQL?
can you search your backup.sql file for the back-ticks and post that section of your file?
it would help to know if your back-ticks are in the column field names or in the data portion of the SQL statement.

Error in executing SQL statement with PostgreSQL

I create a new database 'sakila' with pgAdmin III in my local PostgreSQL database, then executed these sql statements:
sakila-schema.sql then sakila-data.sql
The first statement executed without error, however the second SQL did produced error when executed:
ERROR: syntax error at or near "1"
LINE 112: 1 PENELOPE GUINESS 2006-02-15 09:34:33
^
********** Error **********
ERROR: syntax error at or near "1"
SQL state: 42601
Character: 2511
How to fix this error?
You can't COPY FROM stdin with pgAdmin, you have to use psql tool, the problem is that pgAdmin is not a console application, there is no easily usable stdin so you can't COPY from Standard Input .