Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

Does HSQLDB support default values for enums in MySQL compat mode?

I'm using an in-memory HSQLDB instance (version 2.5.1) for Java unit tests. The instance has MySQL compatibility mode enabled. The following create statement works:

CREATE TABLE people
(
  is_subscribed enum('y','n') NOT NULL
)

However, if I try adding in a default value like this:

CREATE TABLE people
(
  is_subscribed enum('y','n') DEFAULT 'n' NOT NULL
)

I get the following error message:

java.sql.SQLSyntaxErrorException: unexpected token: DEFAULT : line: 3 in statement [CREATE TABLE people

Is there a way to specify a default value for an enum type?

question from:https://stackoverflow.com/questions/65910722/does-hsqldb-support-default-values-for-enums-in-mysql-compat-mode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

HSQLDB versions up to 2.5.1 do not support the DEFAULT clause directly for MySQL ENUM declarations. This may be supported in later versions.

You can add the DEFAULT after the table is created. Use:

ALTER TABLE people ALTER COLUMN is_subscribed SET DEFAULT 'n'

Update: This is now supported in the latest code. You can check out the code and build the jar. The update will appear in the next release.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...