On 13 Jul 2011, at 1:13pm, Amit Chaudhuri wrote:

> I have situation where a column may contain prices (REAL) or a string
> meaning "no price for this, sorry." I can handle this in application code
> but was wondering if I am overlooking a Sqlite feature which might do the
> same out of the box: perhaps a TYPE( ) or an IsText( ) function..?

There is a 'typeof'.  But you didn't know the proper way to do it.  What you do 
is set up the column to be a number format (real or integer, however you hold 
your prices) and use NULL when you don't have a price.  Then you can very 
quickly and easily check for a NULL with

typeof(X) = 'null'
nullif(X,Y)

or convert it to your 'no price for this' string with

ifnull(X,'No price for this, Sorry.')

In fact this is what NULL means in SQL: something like 'data missing' or 'value 
unknown'.  So it is exactly what you really want.  For more details see

<http://www.sqlite.org/lang_corefunc.html>

For how to do calculations on numbers that might be NULL, see

<http://www.sqlite.org/lang_aggfunc.html>

For more details than you need don't bother seeing

<http://www.sqlite.org/nulls.html>

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

Reply via email to