Options for eliminating NULLable columns from a DB model (in order to avoid SQL's three-valued logic)?

后端 未结 7 1465
温柔的废话
温柔的废话 2021-02-08 20:19

Some while ago, I\'ve been reading through the book SQL and Relational Theory by C. J. Date. The author is well-known for criticising SQL\'s three-valued logic (3VL).

7条回答
  •  死守一世寂寞
    2021-02-08 21:06

    You can eliminate null in the output as well by using COALESCE.

    SELECT personid  /*primary key, will never be null here*/
           , COALESCE(name, 'no name') as name
           , COALESCE(birthdate,'no date') as birthdate
    FROM people
    

    Not all databases support COALESCE, but almost all have a fallback option called
    IFNULL(arg1, arg2) or something simular that will do the same (but only for 2 arguments).

提交回复
热议问题