Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: does data type depend on the quotes?

Tags:

sqlite

In SQLite, the datatype of a value is associated with the value itself, not with the column type. So suppose we have a table with an integer primary key "id" and an integer column "some_number". If I do a query like this:

INSERT INTO mytable (id, some_number) VALUES (NULL, "1234")

Will 123 be inserted as an integer or as string? What consequences it will have later for me, say, when I'm comparing it with other value like "234" (as a number 1234 > 234, as a string "1234" < "234", right?)?

like image 717
Septagram Avatar asked Sep 05 '25 23:09

Septagram


1 Answers

if your field type, (some_number), is numeric, then it will be inserted as a numeric value. No matter whether you put quotes.

if some_numeber is numeric

INSERT INTO mytable (id, some_number) VALUES (NULL, "1234")

and

INSERT INTO mytable (id, some_number) VALUES (NULL, 1234)

are same

like image 55
Binil Avatar answered Sep 10 '25 10:09

Binil