0

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.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
ThatGuy343
  • 2,354
  • 3
  • 30
  • 55

3 Answers3

3

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?

Community
  • 1
  • 1
jotadepicas
  • 2,389
  • 2
  • 26
  • 48
1

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

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
1

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)
Ashish Bhavsar
  • 236
  • 4
  • 18