본문 바로가기
DataBase/PostgreSQL

[PostgreSQL] NULLIF

by 김뚱 2019. 8. 13.

NULLIF(exp1, exp2)

- exp1값과 exp2값이 동일하면 NULL을 그렇지 않으면 exp1을 반환
- CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END

 

Test

select count(1) from customers; --10

select count(NULLIF(postalcode, '')) as cnt
from customers; --10

select count(NULLIF(postalcode, '12209')) as cnt
from customers; --9
select count(
	case when postalcode = '' then null 
	else postalcode 
	end
	) as cnt 
from customers; --10

select count(
	case when postalcode = '12209' then null 
	else postalcode 
	end
	) as cnt 
from customers; --9

 

테이블정보는 아래 글 참고

https://jieun0113.tistory.com/127

 

[PostgreSQL] Table Data를 JSON타입으로 만들기

JSON으로 Data를 전송해야하는 경우 쿼리를 이용하여 Table Data를 JSON타입으로 만들 수 있다. Test Case drop table customers; create table customers ( customerID varchar , customerName varchar , contact..

jieun0113.tistory.com

 

Reference

http://www.gurubee.net/lecture/1880

 

NVL, NVL2, NULLIF, COALESCE

NVL NVL 함수는 NULL 값을 다른 값으로 바꿀 때 사용하며, 모든 데이터 타입에 적용이 가능하다. -- 매니저가 없는 값을 0으로 바꾸어서 출력..

www.gurubee.net

 

728x90
반응형

댓글