sqlite3 Error when Running in Terminal - sql

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.

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.

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.

Error in loading the file into the table

load DATA LOCAL
infile 'C:\Users\abcdefg.h.ABCINDIA\datafile.csv'
INTO TABLE XXSYMC.invoice_demo
fields terminated BY " " optionally enclosed BY '"'
(invoice_number,org_id,supplier_id);
I get the error as shown below:
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
SQL Developer is for running SQL statements and PL/SQL code. What you're trying to run is SQL*Loader control file syntax.
They are completely different tools, and you cannot run SQL*Loader commands from SQL Developer. If you want to load that file you can use the SQL*Loader command line.
If the file is available on the database server you could create an external table instead, and copy the data from that into your real table; you could at least do that from SQL Developer, as long as you have the right permissions and can put the file in a server directory that Oracle recognises...

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.