lukik
lukik

Reputation: 4060

SQLite Store strings that start with zero e.g. "001"

Which data type do I choose in SQLite to store a string such as "001" in the database.

I've tried using Text but when I go to type in the string 001, it drops the 00 and only puts a 1.

I've even tried using "blob" data type but still no luck. They all drop the zeros before the digit.

Upvotes: 2

Views: 2728

Answers (2)

chenxi
chenxi

Reputation: 31

Column type should set to varchar, not string, if type is string zero will be dropped automatically.

Upvotes: 2

Phil
Phil

Reputation: 2422

Works ok for me:

sqlite> create table sotest
   ...> (
   ...> col1 varchar(20)
   ...> );
sqlite>
sqlite> select * from sotest;
sqlite>
sqlite> insert into sotest values ('001');
sqlite> select * from sotest;
001
sqlite>

Maybe you weren't quoting your strings? For example:

sqlite> insert into sotest values ('001');
sqlite> select * from sotest;
001
sqlite> insert into sotest values (001);
sqlite> select * from sotest;
001
1
sqlite>

Upvotes: 6

Related Questions