2017-04-21 57 views

回答

1

是的,有IS DISTINCT FROM and IS NOT DISTINCT FROM

postgres=# \pset null **** 
Null display is "****". 
postgres=# select null = null; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ ****  │ 
└──────────┘ 
(1 row) 

postgres=# select null is not distinct from null; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ t  │ 
└──────────┘ 
(1 row) 

postgres=# select 10 = null; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ ****  │ 
└──────────┘ 
(1 row) 

postgres=# select 10 is distinct from null; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ t  │ 
└──────────┘ 
(1 row) 

postgres=# select 10 is not distinct from null; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ f  │ 
└──────────┘ 
(1 row) 

postgres=# select 10 is not distinct from 20; 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ f  │ 
└──────────┘ 
(1 row) 
0

沒有,但你可以使用a.unitnum = b.unitnum或(a.unitnum爲null並且b.unitnum爲null)

1

是,there is,但it is recomended to not use it。這裏是示例:

t=# select null = null; 
?column? 
---------- 

(1 row) 

t=# set transform_null_equals = on; 
SET 
t=# select null = null; 
?column? 
---------- 
t 
(1 row) 

UPDATE:顯然將只工作比較column = NULL,不列=列:

t=# with s as (select null::int a, null::int b) select a <> b from s; 
?column? 
---------- 

(1 row) 

所以最短的比較就聚結:

t=# with s as (select null::int a, null::int b) select coalesce(a,b,0) = 0 from s; 
?column? 
---------- 
t 
(1 row) 
+0

kha!它不比較兩列:) –

+0

我得到COALESCE類型的文本和整數不能匹配 –

+0

啊,我懷疑它可能是所有 - 不知道是否有'運營商文本=整數'。無論如何,你需要'coalesce(text_colun,int_column :: text,'null')='null'' –