Mandroid
Mandroid

Reputation: 7468

SQL Error during Spring boot start for creating table for H2

Following is the SQL to create a table:

create table if not exists Product (
id int identity(1, 1),
name varchar(50) not null,
price float (7, 2) not null,
description varchar(100) not null);

It gives error while its executed during Spring boot start:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS PRODUCT ( ID INT IDENTITY(1, 1), NAME VARCHAR(50) NOT NULL, PRICE FLOAT (7,[*] 2) NOT NULL, DESCRIPTION VARCHAR(100) NOT NULL )"; expected ")";

Upvotes: 1

Views: 921

Answers (1)

Evgenij Ryazanov
Evgenij Ryazanov

Reputation: 8178

You have an incorrect column data type definition. FLOAT data type has only one parameter: the minimal required binary precision (in bits). This data type is also an approximate precision data type and can't be used for currency values.

You need to use the NUMERIC (7, 2) data type instead.

Upvotes: 0

Related Questions