IF() statement alternative in SQLite

前端 未结 3 984
甜味超标
甜味超标 2020-12-03 06:57

I have the code for MySQL (perl):

UPDATE pages
SET rkey = rkey + 2,
    lkey = IF(lkey >= $key, lkey + 2, lkey)
WHERE rkey >= $key

I

3条回答
  •  感动是毒
    2020-12-03 07:19

    SQLite version 3.32.0 and newer support IIF.

    iif(X,Y,Z)

    The iif(X,Y,Z) function returns the value Y if X is true, and Z otherwise.

    The iff(X,Y,Z) function is logically equivalent to and generates the same bytecode as the CASE expression "CASE WHEN X THEN Y ELSE Z END".


    E.g.

    UPDATE pages
    SET rkey = rkey + 2,
        lkey = IIF(lkey >= $key, lkey + 2, lkey)
    WHERE rkey >= $key;
    

提交回复
热议问题