> -----Original Message-----
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Shorty
> Sent: 12 October 2011 09:31
> 
> -- HERE IS MY QUESTION: --
> Is faster for the sqlite database to have the grocery_type as a string or
> integer?
> Or is the speed difference so small it doesn't matter?
> 
> Like instead of having "fruit" in the grocery_type column, I could have it
as a
> "1" type, vegetables would be "2", and then translate that just before
> spitting out the table to my web page.
> 

I think that the sorting itself would be faster with an integer rather than
string.
However, with the small number of items that you mention here the difference
would probably be immeasurably small. Also, if you were to use an integer it
would, as you mention, have to later be converted to a string which also
takes time.

Generally, I go with the ease of use (i.e. use a meaningful string rather
than an integer) unless it is a database where performance or storage space
is an issue, which could be an another advantage of using integers with
reference to a lookup table of strings, if e.g. your database contains other
large tables with many records referring to these fruits, vegetables or
other items.

It's somewhat similar to the issue with dates. You can store them as Julian
numbers which is more effective, but then you have the hassle of having to
use date function in the select statement for the result to be meaningful.
Thus, unless there is a storage or performance issue I just store the dates
as strings, e.g. '2011-10-12'. 

/Frank Missel


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to