Re: [sqlite] CASE and NULL

2018-07-05 Thread Peter Johnson
Can't you just use IFNULL to assign a default value? CASE IFNULL( x, -999 ) WHEN 1 THEN 11 WHEN 2 THEN 22 WHEN 3 THEN 33 WHEN 4 THEN 44 WHEN -999 THEN 55 ELSE 66 END On 5 July 2018 at 11:35, R Smith wrote: > On 2018/07/05 8:44 AM, Simon Slavin wrote: > >> On 5 Jul 2018, at 7:30am,

Re: [sqlite] CASE and NULL

2018-07-05 Thread R Smith
On 2018/07/05 8:44 AM, Simon Slavin wrote: On 5 Jul 2018, at 7:30am, Clemens Ladisch wrote: The expression "x = x" will fail for NULL, but succeed for everything else. So you can use that to implement a "not-NULL ELSE" Wow. That has to be the most counter-intuitive feature of SQLite. I

Re: [sqlite] CASE and NULL

2018-07-05 Thread Keith Medcalf
On Thursday, 5 July, 2018 00:57, Donald Shepherd : >On Thu, 5 Jul 2018 at 16:45, Simon Slavin >wrote: >> On 5 Jul 2018, at 7:30am, Clemens Ladisch >wrote: >>> The expression "x = x" will fail for NULL, but succeed for >>> everything else. So you can use that to implement a >>> "not-NULL

Re: [sqlite] CASE and NULL

2018-07-05 Thread Donald Shepherd
On Thu, 5 Jul 2018 at 16:45, Simon Slavin wrote: > On 5 Jul 2018, at 7:30am, Clemens Ladisch wrote: > > > The expression "x = x" will fail for NULL, but succeed for everything > > else. So you can use that to implement a "not-NULL ELSE" > > Wow. That has to be the most counter-intuitive

Re: [sqlite] CASE and NULL

2018-07-05 Thread Simon Slavin
On 5 Jul 2018, at 7:30am, Clemens Ladisch wrote: > The expression "x = x" will fail for NULL, but succeed for everything > else. So you can use that to implement a "not-NULL ELSE" Wow. That has to be the most counter-intuitive feature of SQLite. I understand why it works, but I still don't

Re: [sqlite] CASE and NULL

2018-07-05 Thread Clemens Ladisch
Andy Goth wrote: > The expression "x = NULL" is meaningless since it will always evaluate > to NULL, which CASE interprets as untruth, hence "WHEN NULL THEN" will > never accomplish anything. > [...] > So I'm wondering: can we do better? The expression "x = x" will fail for NULL, but succeed for

Re: [sqlite] CASE and NULL

2018-07-04 Thread Simon Slavin
On 5 Jul 2018, at 6:22am, Andy Goth wrote: > Or equivalently, "ISNULL" instead of "IS NULL". There is no ISNULL in sqlite3. Also, the functions ifnull() and nullif() are not useful for actually testing for NULL. Continuing to eliminate options, regular expressions do not match with NULL in

[sqlite] CASE and NULL

2018-07-04 Thread Andy Goth
I'd like to use CASE to compare an expression x against a number of candidate values. That's the typical use for "CASE x WHEN", which avoids repeating x for each condition. The trouble is that one of the possible values is NULL, yet the comparison against each candidate value is done with