ThatGuy343
ThatGuy343

Reputation: 2424

Unknown syntax error in MySQL statement

I am using below CREATE TABLE statement

CREATE TABLE IF NOT EXISTS users (
`uuid` varchar(36) NOT NULL,
`json` varchar(MAX) NOT NULL,
PRIMARY KEY (`uuid`)
);

However I keep getting this error.

ERROR 1064 (42000): 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 'MAX) NOT NULL, PRIMARY KEY (uuid) )' at line 3

Makes no sense to me.

Upvotes: 0

Views: 3011

Answers (3)

Ashish Bhavsar
Ashish Bhavsar

Reputation: 236

MAX() is a function in MySql,So if you want to declare the size to the max.please refer the below example.

CREATE TABLE IF NOT EXISTS users (
`uuid` varchar(36) NOT NULL,
`json` varchar(65535) NOT NULL,
PRIMARY KEY (`uuid`)
);

and if you calculate that 21845*3 = 65535, which wouldn't have worked anyway.
Whereas 21844*3 = 65532, which does work.

mysql> CREATE TABLE foo ( v VARCHAR(21844) ) CHARSET=utf8;
Query OK, 0 rows affected (0.32 sec)

Upvotes: 1

HaveNoDisplayName
HaveNoDisplayName

Reputation: 8517

This will work for you. MAX is reserved keyword. Specify exact number of varchar instead of max. However, varchar(MAX) will work in SQL SERVER 2005+.

CREATE TABLE IF NOT EXISTS users (
  uuid varchar(36) NOT NULL,
  json varchar(21808) NOT NULL,
  PRIMARY KEY (uuid)
);

FIDDLE

Upvotes: 1

jotadepicas
jotadepicas

Reputation: 2493

MAX is not suported for this use, it is reserved for the MAX function. Use the equivalent number instead, check this out: Equivalent of varchar(max) in MySQL?

Upvotes: 3

Related Questions