본문 바로가기

DataBase/PostgreSQL10

[PostgreSQL] Sequence 시작값 변경 ALTER SEQUENCE 시퀀스명칭 restart with 7; 2020. 3. 6.
[PostgreSQL] COALESCE 함수 (Null 체크) 문법 COALESCE (컬럼, 대체 값) 설명 대체 값은 컬럼이 null인 경우 대체 값으로 반환한다. (다른 컬럼으로 대체할 수 있다. ) PostgreSQL ORACLE MSSQL COALESCE(param1, param2) NVL(param1, param2) ISNULL(param1, param2) 대체 방법 1. 컬럼 coalesce(name, id) as name 2. 지정 문자열 coalesce(name, 'No Data') as name 3. null coalesce(name, null) as name 4. json coalesce(name, '{}')::json as name 출처: https://xshine.tistory.com/205 [메모하는습관] 2019. 9. 5.
[PostgreSQL] NULLIF 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 c.. 2019. 8. 13.
[PostgreSQL] Table Data를 JSON타입으로 만들기 JSON으로 Data를 전송해야하는 경우 쿼리를 이용하여 Table Data를 JSON타입으로 만들 수 있다. Test Case drop table customers; create table customers ( customerID varchar ,customerName varchar ,contactName varchar ,address varchar ,city varchar ,postalCode varchar ,country varchar ); insert into customers values ('1', 'Alfreds Futterkiste', 'Maria Anders', 'Obere Str. 57', 'Berlin', '12209', 'Germany'); insert into customers va.. 2019. 8. 12.