NULL compare operator <=>
MySQL
SELECT 99 <=> NULL, NULL <=> NULL;
+-------------+---------------+
| 99 <=> NULL | NULL <=> NULL |
+-------------+---------------+
| 0 | 1 |
+-------------+---------------+
IS NULL
IS NOT NULL
PostgreSQL
针对不同的类型,需要创建不同的函数 和 <=>
create or replace function nulleq(int,int) returns int as
$$
declare
begin
if $1 is null and $2 is null then
return 1;
else
return 0;
end if;
end;
$$
language plpgsql;
postgres=# create operator <=> (procedure=nulleq,leftarg=int,rightarg=int);
CREATE OPERATOR
postgres=# select 1 <=> null;
?column?
----------<