tgoop.com/rzv_de/316
Create:
Last Update:
Last Update:
Впервые за 6 лет узнал об этой конструкции SQL
upd: расходимся, это не ANSI-SQL. не рекомендую вставлять на проект, потому что однажды точно случится миграция
позволяет сравнивать значения с учётом null. Если одно из значений — null, значит другое not-null значение не будет ему равно. Ведёт себя немного иначе, по сравнению с
is distinct from= null
, is null
.
col1 is distinct from col2
Более стандартный подход:
CASE WHEN (col1 = col2) or (col1 IS NULL AND col2 IS NULL)
THEN false
ELSE true
END
Ну и код чтобы поиграться локально на postgres (см. картинку):
with my_data as (
select null as col
union all
select 'null'
)
select
col
,col = null as c1
,col = 'null' as c2
,col != null as c3
,col != 'null' as c4
,col is null as c5
,col is not null as c6
,col is distinct from null as c7
,col is distinct from 'null' as c8
,col is not distinct from null as c9
,col is not distinct from 'null' as c10
from my_data
BY rzv Data Engineering

Share with your friend now:
tgoop.com/rzv_de/316