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.

5
  • max is a reserved word. how about theMax...no how about a number Commented Jun 7, 2015 at 0:10
  • even without (MAX) i get the error. Commented Jun 7, 2015 at 0:11
  • 1
    varchar(60000) ?, varchar(255) ? Commented Jun 7, 2015 at 0:11
  • that worked, however is converting the row json from varchar to text. Commented Jun 7, 2015 at 0:13
  • sorry i was messing with 60000 once on a dif server to check max but that high i would Text for purposes mainly FULLTEXT search. typically it is like 100 or 255 (<1001) Commented Jun 7, 2015 at 0:56

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.