views:

1338

answers:

3

does anyone know if sqlite supports the sql function "if" in the select..

for example

select if( length( a ) > 4 , a , ' ') as b
from foo

which would return a if the length was over 4 chars long.. or else it would return ' ' as b

if it doe support a condition in the select what is the syntax is should be using?

i have checked http://sqlite.org/lang%5Fcorefunc.html but i cant see it.

A: 

I don't believe it does. You can create your own user written functions if you really require it to be done that way. Otherwise I'd just look at doing it within your application

Jay
+3  A: 

See the case expression For your example

select case when length(a) > 4 then a else '' end as b
from foo
Mark
+2  A: 

You can use case for that:

select case when length(a)>4 then a else ' ' end from foo;
Paul Dixon
Odd; the link doesn't work for iceweasel. It will cause a Document Not Found Error (/lang_5Fexpr.html). The address in the address-bar will be the correct one though (.../lang_expr.html). Not sure why that is. Although the address is correct, a refresh won't work; have to hit enter in the address bar to get the page.
Inshallah
markdown doesn't like underscores I guess. I have changed the link to use the snurl redirector
Paul Dixon