psql restore sql dump syntax error - sql

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.

Related

Simple Syntax Error in SQLite: "Error near line 1: near "SQLite"

I am having a great deal of trouble with this seemingly simple issue. I can't seem to get .read to work. Here is the code that I have tried:
Any help would be greatly appreciated!
.open test.sql
This opens a Sqlite3 database (Creating a new one if the file doesn't already exist) and attaches it as the main one in the sqlite3 shell session.
.read test.sql
This attempts to read a text file full of SQL statements and execute them one by one.
A sqlite database is not a text file full of SQL statements, hence the syntax errors when you try to treat it as one.
The correct syntax is:
CREATE TABLE t (x int);
or
CREATE TABLE t (x INTEGER);
Read more about the CREATE statement and data types.

Symfony 4 - SQLSTATE[42000] alter table for unknown reasons

I'm here because, I need your help. I'm working on a Symfony project, I just finished to modify my DataBase with MySqlWorkBench (I've done this because I have to present the DataBase at the end of the school year). After that, I've executed "Forward Engineer" to send all the tables and columns to the database.
Then, i've just entered this line, to create my entities:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
Later I put this line line to generate my setters/getters and my Repositories
php bin/console make:entity --regenerate App
When it's done, I've used those lines :
php bin/console d:m:diff
And I migrate all to the database:
php bin/console d:migrations:execute --up 20190321194410
And after this command, I got a ton of errors but they deal of the same thing.
There is this query, I don't know why it's executed:
ALTER TABLE school_has_level RENAME INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE
And after there is those errors :
In AbstractMySQLDriver.php line 79:
An exception occurred while executing 'ALTER TABLE school_has_level RENAME INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serve
r version for the right syntax to use near 'INDEX fk_school_has_school_level_school1_idx TO IDX_102C1F10C32A47EE' at line 1
I'm searching some tips on Internet but I didn't find anything about that. The problem is that, I don't understand where the query is started...
Thank you for your future answer, and sorry for my english :'(
Best regards,
Mathieu

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

sqlite3 Error when Running in Terminal

I have a .sql file called create.sql. It consists of the following lines:
drop table if exists Items;
drop table if exists Auctions;
create table Items(...);
create table Auctions(...);
When I run:
sqlite3 test < create.sql
It crashes and says, "Error: near line 1: near "drop": syntax error"
Any thoughts?
I just tried this SQL Fiddle, there is no problem with the SQL syntax
The problem seems to be with the way the file is created and looks to be platform specific
if you are using Notepad++ or other editors, try converting the file to Unix style EOL i.e. \n, the file might be having \r\n which sqllit3 is complaining about.

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.