1

I am using sqlite3 and I came across a strange issue. For example, I have the following table.

CREATE TABLE demo (effort integer);


insert into demo values (10.5);  - works fine
insert into demo values (10.5);  - works fine
insert into demo values (10.5555);  - works fine

I have two concerns:

1.Why is it allowing float values when I have declared the datatype to be integer not real ? 2.Is there any way, that I can restrict it upto 2 decimal places?

Is there any workaround so that I can restrict only integer values(strictly no floating values).

Please suggest.

1 Answer 1

1

SQLite uses dynamic typing.

To enforce the column type, add a constraint:

CREATE TABLE demo(
  effort INTEGER NOT NULL CHECK(typeof(effort) = 'integer')
)
Sign up to request clarification or add additional context in comments.

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.