All thing of the world!

Postgresql jsonb_set 설명 : 포스트그레스큐엘 함수 본문

IT/Postgresql DBMS

Postgresql jsonb_set 설명 : 포스트그레스큐엘 함수

WorldSeeker 2021. 4. 28. 10:52

1. 함수의 목적

   

    Postgresql jsonb_set 함수는 json에 관련된 함수로서, target으로 들어온 jsonb를 new_value로 들어온 인수로 변환한다. 이 때 create_if_missing가 true라면 변경하지 않고 new_value가 추가된다.

 

2. 샘플을 통한 개념 퀵뷰

 

    SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]',  '{0,f1}''[2,3,4]', false);

 

    jsonb_set

    ------------

    [{"f1": [2, 3, 4], "f2": null}, 2, null, 3]

 

 

3. 사용방법

 

    jsonb_set ( target jsonb, path text[], new_value jsonb [, create_if_missing boolean ] ) 

 

    

4. 함수 PARAMETER 설명

 

[target jsonb]

변환할 source jsonb를 입력한다.

 

[path text[]]

path를 text배열로 입력한다.

 

[new_value jsonb]

치환할 target jsonb를 입력한다.

 

[create_if_missing boolean] - 선택적 인수, default는 true

true로 설정하면 new_value가 추가, false로 설정하면 new_value로 변경

 

5. 다양한 샘플 표현

 

 

 

 Posgresql 내장함수 모음 : atotw.tistory.com/category/IT/Postgresql%20DBMS

 

Comments