Does sqlite support the sql function "if" in the select statement?
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 does support a condition in the select what is the syntax is should be using?
I have checked http://sqlite.org/lang_corefunc.html but I can't see it.
In SQLite, iif() is a conditional function that returns the second or third argument based on the evaluation of the first argument. It's logically equivalent to CASE WHEN X THEN Y ELSE Z END . iif() is an abbreviation for Immediate IF. The iif() function was introduced in SQLite 3.32.
SQLite provides two forms of the CASE expression: simple CASE and searched CASE .
The OR operator is also used to combine multiple conditions in a SQLite statement's WHERE clause. While using OR operator, complete condition will be assumed true when at least any of the conditions is true. For example, [condition1] OR [condition2] will be true if either condition1 or condition2 is true.
SQLite Numeric expression is used to perform any mathematical operations in the query.
See the case expression.
A CASE expression serves a role similar to IF-THEN-ELSE in other programming languages.
For your example
select case when length(a) > 4 then a else '' end as b from foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With