Search code examples
mysqlsqlentityworkbenchpowerdesigner

MySQL Workbench out of range value for decimal number


I wanted to create an table

create table Oceny_projekty
(
   OProj_Id             int not null  comment '',
   ID_Projektu          int  comment '',
   ID_Studenta          int  comment '',
   OProj_Ocena          decimal(1,1)  comment '',
   OProj_Data           date  comment '',
   primary key (OProj_Id)
);

And fill it with sample data generated by PowerDesigner

insert into Oceny_projekty (OProj_Id, ID_Projektu, ID_Studenta, OProj_Ocena, OProj_Data)
    values (2, 18, 10, '2.5', '1857-12-25');

And I've got this:

insert into Oceny_projekty (OProj_Id, ID_Projektu, ID_Studenta, OProj_Ocena, OProj_Data) values (2, 18, 10, '2.5', '1857-12-25') Error Code: 1264. Out of range value for column 'OProj_Ocena' at row 1

How can I modify command that can accept decimal numbers? (with integer numbers there is no problem) Using MySQL Workbench 6.3, PowerDesigner 16.6

Thanks in advance!


Solution

  • Declaring OProj_Ocena as decimal(1,1) means that it has 0 integer digits (precision - scale = 1 - 1 = 0) and 1 fractional digit. It can only store values 0, 0.1, 0.2 ... 0.9.

    The datatype you need is probably decimal(2,1).