Syntax errors whilst creating a table in MonetDB - sql

This is driving me mad and I'm at the point where I'm thinking I must just be missing something very obvious. We are setting up a MonetDB environment with SQiurrel. I though the challenge would be wiring that all up and getting the drivers to work, but as it turns out that is running and I can see the DB in all its glory.
I have a DB in MySQL that I need to rebuild so I just generated the code:
CREATE TABLE "some_database"."some_table" (
key int(11) NOT NULL AUTO_INCREMENT,
column_1 varchar(10) DEFAULT NULL,
column_2 varchar(10) DEFAULT NULL,
column_3 varchar(10) DEFAULT NULL,
column_4 varchar(10) DEFAULT NULL,
column_5 varchar(10) DEFAULT NULL,
column_6 int(11) DEFAULT NULL,
column_7 decimal(10,2) DEFAULT NULL,
column_8 decimal(10,2) DEFAULT NULL,
column_9 int(11) DEFAULT NULL,
PRIMARY KEY (key)
) ENGINE=InnoDB AUTO_INCREMENT=20189170 DEFAULT CHARSET=utf8;
The only difference is that I've changed the column and table names. I'm not sure if this is all compatible for a start but I figured I would just work my way around it as it chucked errors. The first was about using a `. MonetDB seems to not like you.
I removed those and now I get:
Error: syntax error, unexpected '(', expecting ')' or ',' in: "create table "some_database"."some_table" (
SQLState: 42000
ErrorCode: 0
Error: fact_key int("
SQLState: 22000
ErrorCode: 0
For the "key" column I'm also getting the int(11) turn red and tell me I have an "EOF Expected"
If I quickly type out my own CREATE TABLE statement I can create a tables with a type varchar. As soon as I add in an int type it goes mad again.
So for example I just created this table in MonetDB:
CREATE TABLE "some_database"."some_table"
(
something varchar(10),
something2 varchar(10)
);
That worked fine. As soon as I add an int type:
CREATE TABLE "some_database"."some_table"
(
something varchar(10),
something2 varchar(10),
something3 int(10)
);
It goes a bit mental again:
Error: syntax error, unexpected '(', expecting ')' or ',' in: "create table "some_database"."some_table"
SQLState: 42000
ErrorCode: 0
Error: (
SQLState: 22000
ErrorCode: 0
Error: something varchar(10),
SQLState: 22000
ErrorCode: 0
Error: something2 varchar(10),
SQLState: 22000
ErrorCode: 0
Error: something3 int("
SQLState: 22000
ErrorCode: 0
So my question is have I set something up wrong? MonetDB seems to be running well and I can explore everything as one would expect in SQiurrel. I can create basic tables with varchar but as soon as I bring in an int the computer says no. I also don't understand what EOF means? I assumed it was expecting an , but it has that?
Thanks in advance. I'm hoping I just need a fresh mind who knows MonetDB to tell me why I'm missing the obvious!

I think I've worked out my issue. Hopefully someone who is learning their way around MonetDB may find this and save themselves some effort.
The syntax for an int is different.
Rather than:
int(11)
You must just type:
int
Once I removed the (11) from each int in my create statement it ran.

Related

Error in simple SQL when executing in python

I'm getting an error with this SQL code when I execute it in my Flask app. I swear I've done this exact thing before and it worked, so I'm not sure what's happening.
Here is the SQL:
DROP TABLE IF EXISTS user;
CREATE TABLE order (
id TEXT PRIMARY KEY,
plan_id INTEGER NOT NULL,
placed TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ssh_key TEXT NOT NULL,
region INTEGER NOT NULL,
operating_system INTEGER NOT NULL,
enable_ipv6 INTEGER NOT NULL
expires INTEGER NOT NULL
);
Here is the relevant part of my python error:
sqlite3.OperationalError: near "order": syntax error
Thank you for the help
Order is a reserved keyword for sqlite. If you want to use a keyword as a name, you need to quote it.
https://www.sqlite.org/lang_keywords.html

PostgreSQL syntax error at or near INT

I made a script to create a database with PostgreSQL.
So I copy in my script, click "Analyze & Explain" in pgAdmin4 and I have no clue why it says I have a syntax error at or near 'INT' on idSituationFamiliale.
I really can't see what's wrong...
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INT NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);
The query is fine if you RUN it. It is wrong if you EXPLAIN / ANALYZE it.
The doc says that you can explain a CREATE TABLE AS, not a pure CREATE TABLE statement. While the former contains a SELECT statement that can be explained/analyzed, the later has nothing to be explained/analyzed and fails on the 1st field, regardless of its name or type.
You should be using integer as opposed to int.
e.g
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INTEGER NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);

SQL syntax error

I use phpMyAdmin and want to create a table. I use the visual interface for creating the table but I'm gonna post the code from "Preview SQL" option:
CREATE TABLE `baza`.`koncert` (
`koncert_id` INT(10) NOT NULL AUTO_INCREMENT ,
`koncert_naziv` VARCHAR(50) NULL ,
`koncert_lokacija` VARCHAR(50) NOT NULL ,
`koncert_datum` DATE NULL DEFAULT NULL ,
`koncert_cijena` DOUBLE(10) NOT NULL ,
`koncert_slika` VARCHAR(500) NOT NULL )
ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_croatian_ci;
And I get this error:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near ')' NOT NULL, 'koncert_slika' VARCHAR(500) NOT NULL ) ENGINE=InnoDB CHARSET=ut
I tried setting the 'koncert_datum' default value to CURRENT_TIMESTAMP, but then I get an error "Invalid default value for 'koncert_datum'". I just don't understand what could possibly be wrong (and I used the phpMyAdmin visual interface to try create the table!)
According to the documentation https://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html the DOUBLE type needs total digits and decimal digits. Something like
`koncert_cijena` DOUBLE(12,2) NOT NULL ,
Check the schema and ensure baza.koncert is present and try running them by removing "ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_croatian_ci" this.

PHPmyadmin won't accept CREATE TABLE statement

I'm trying to use a simple CREATE TABLE statement to create a new table in my very first SQL-database. PHPmyadmin won't accept the code and gives me an error statement.
There doesn't appear to be anything wrong with the syntax of my SQL command. In fact, I receive the same error statement when I copy and past an example code from any internet tutorial to create a table.
this is my SQL command:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0,
)
This is the error statement:
Static analysis:
3 errors were found during analysis.
A symbol name was expected! (near "Name" at position 74)
Unexpected beginning of statement. (near "50" at position 87)
Unrecognized statement type. (near "NOT NULL" at position 91)
SQL query:
CREATE TABLE Guestbook( ID int AUTO_INCREMENT PRIMARY KEY NOT NULL, Name varchar(50) NOT NULL, Message TEXT NOT NULL, Date datetime, Sport varchar(30), Practicioner BOOLEAN default 0, )
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 8
I can't imagine why this won't work. I'd like to be able to use to command line in phpMyadmin. and this seems pretty straigtht forward. Yet I've been fiddling around with it for ages and I can't figure out how to create even the simplest possible table.
Can anyone help me out?
You should remove the last comma in your CREATE statement:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0
)

Can't create new table

I'm new to SQL Server 2000 and face a problem. I want to make a new table but I encounter an error message with the following code:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10)not null,
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30) default,
Tahun_Terbit varchar(4) default,
Bahasa varchar(4) check,
Harga_Jual money,
)
and here's the error code:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'Buku'.
You have three problems:
You have multiple cases where you say default but don't specify anything
You have a check but don't specify anything
Your last column definition says money, with a trailing comma
Now, none of these lead to the exact error message you're getting, so maybe there is more you're not telling us (is there more code before the create table bit?), but these little syntax problems are far too localized to be useful in this Q & A format.
EDIT
I just ran this on a SQL Server 2000 instance and it worked just fine:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10) not null, -- added space here
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30), -- removed default here
Tahun_Terbit varchar(4), -- removed default here
Bahasa varchar(4), -- removed check here
Harga_Jual money -- removed comma here
)
So I'm not sure what you're doing differently, but I can't get the error message you are seeing with the information you've provided in the question. If you're still getting an error message with this code (and only this code), you'll need to provide more information, such as ##VERSION, what interface you're using to submit the create table statement to SQL Server, etc.