Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread James K. Lowden
On Tue, 7 Oct 2014 12:15:09 +0300 "Tony Papadimitriou" wrote: > Is there any an equivalent function to the MySQL > IF(condition,true_expr,false_expr) function? > > For example, SELECT AGE,IF(AGE < 3,"BABY",IF(AGE < > 18,"CHILD","ADULT")); > > If not, please add to wish list :)

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
Totally agree. And this is exactly why my natural first reaction was to expect a syntax error, because in my mind you can't compare a non-boolean expr to a boolean expr. I need to start C-ing everything differently. Not easy... :) Thank you (and I didn't imply there was malice, ... just a

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread RSmith
On 2014/10/07 13:20, Tony Papadimitriou wrote: Well, it is exactly because I understand the difference between a boolean expression and a non-boolean expression, along with a bit misleading documentation, that I got confused. It is usually those who are used to only the C-like treatment of a

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
Well, it is exactly because I understand the difference between a boolean expression and a non-boolean expression, along with a bit misleading documentation, that I got confused. It is usually those who are used to only the C-like treatment of a boolean result as being equivalent to an

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread RSmith
On 2014/10/07 12:13, Tony Papadimitriou wrote: Thanks. It seems quite a bit more verbose than the IF() function, but it works, so I can't complain. As an aside - It's not only a little more verbose, it also happens to be the way prescribed by the SQL standard and to my knowledge MySQL,

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread RSmith
On 2014/10/07 12:42, Tony Papadimitriou wrote: You're right, ... but in that page it says: The only difference between the following two CASE expressions is that the x expression is evaluated exactly once in the first example but might be evaluated multiple times in the second: CASE x

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
OK, I think I managed to figure out what it means by reading a little more about the two CASE cases. 'CASE expr WHEN' compares the base expr with the WHEN expr, whereas 'CASE WHEN' compares the WHEN expr to true So, the difference is more than just how many times 'x' is evaluated. (Maybe the

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
You're right, ... but in that page it says: The only difference between the following two CASE expressions is that the x expression is evaluated exactly once in the first example but might be evaluated multiple times in the second: CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Constantine Yannakopoulos
On Tue, Oct 7, 2014 at 1:13 PM, Tony Papadimitriou wrote: > As you can see, the second select gives unexpected output, and according > to the syntax diagram it's not supposed to be a valid variation of the CASE > statement. Is that normal?

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
Thanks. It seems quite a bit more verbose than the IF() function, but it works, so I can't complain. I played with it a bit, and I did notice there are two forms: CASE expr WHEN and CASE WHEN When I accidentally put an expr (CASE expr WHEN) *AND* explicit WHEN conditions rather than

Re: [sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread RSmith
SELECT CASE WHEN (AGE<3) THEN 'Baby' WHEN (AGE BETWEEN 4 AND 18) THEN 'Child' ELSE 'Adult' END On 2014/10/07 11:15, Tony Papadimitriou wrote: Hi all, Is there any an equivalent function to the MySQL IF(condition,true_expr,false_expr) function? For example, SELECT AGE,IF(AGE <

[sqlite] Is there equivalent to MySQL IF() function?

2014-10-07 Thread Tony Papadimitriou
Hi all, Is there any an equivalent function to the MySQL IF(condition,true_expr,false_expr) function? For example, SELECT AGE,IF(AGE < 3,"BABY",IF(AGE < 18,"CHILD","ADULT")); If not, please add to wish list :) TIA ___ sqlite-users mailing list