While ORACLE does state that COALESCE will short circuit, SQLite does not.

May I suggest implementing your own user defined function to do this instead.

void THROW_IF_NULL(
    sqlite3_context *ctx,
    int argc,
    sqlite3_value**argv) {

    int ii;

    for( ii == 0; ii < argc; ii++)
    {
        if (sqlite3_value_type(argv[ii]) != SQLITE_NULL)
        {
            sqlite3_result_value(ctx,argv[ii]));
            return;
        }
    }

    sqlite3_result_error(ctx,"NULL or empty", SQLITE_TRANSIENT);
}

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von Justin Ng
Gesendet: Mittwoch, 11. März 2020 16:24
An: sqlite-users@mailinglists.sqlite.org
Cc: 
vi1p195mb06545f03a24d50dd2785ac2bde...@vi1p195mb0654.eurp195.prod.outlook.com
Betreff: [EXTERNAL] Re: [sqlite] COALESCE() does not short-circuit sometimes

> Why do you think that that it should not evaluate ABS?  It is there and you 
> asked for it.  I believe it's a good idea to say, "hey, the amount you placed 
> here is out of boundary, think about what you are doing here." IMO, of 
> course. Thanks.
>
> josé

Sometimes, when querying data, rather than letting NULLs propagate, it might be 
better to throw an error if NULLs are not expected from an expression.

The presence of NULLs might indicate an error in logic, data, or both.

So, the COALESCE(x, ABS(-9223372036854775808)) construct is a hack to 
sanity-check queries.

Something like THROW_IF_NULL(x)
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | 
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 
1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to