RZV_DE Telegram 316
Впервые за 6 лет узнал об этой конструкции SQL

upd: расходимся, это не ANSI-SQL. не рекомендую вставлять на проект, потому что однажды точно случится миграция

is distinct from
позволяет сравнивать значения с учётом null. Если одно из значений — null, значит другое not-null значение не будет ему равно. Ведёт себя немного иначе, по сравнению с = 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



tgoop.com/rzv_de/316
Create:
Last Update:

Впервые за 6 лет узнал об этой конструкции SQL

upd: расходимся, это не ANSI-SQL. не рекомендую вставлять на проект, потому что однажды точно случится миграция

is distinct from
позволяет сравнивать значения с учётом null. Если одно из значений — null, значит другое not-null значение не будет ему равно. Ведёт себя немного иначе, по сравнению с = 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

View MORE
Open in Telegram


Telegram News

Date: |

The best encrypted messaging apps When choosing the right name for your Telegram channel, use the language of your target audience. The name must sum up the essence of your channel in 1-3 words. If you’re planning to expand your Telegram audience, it makes sense to incorporate keywords into your name. Each account can create up to 10 public channels The group also hosted discussions on committing arson, Judge Hui said, including setting roadblocks on fire, hurling petrol bombs at police stations and teaching people to make such weapons. The conversation linked to arson went on for two to three months, Hui said. Telegram Android app: Open the chats list, click the menu icon and select “New Channel.”
from us


Telegram rzv Data Engineering
FROM American