2017-10-11 1 views

답변

1

우리는 JSON_POPULATE_RECORD와 함께 UPDATE 쿼리를 사용할 수 있습니다. 다음은 테스트로 사용되고 데이터 유형 문자가 가변 인 세 개의 열 a, b, c가있는 예제 테이블 이름의 예입니다.

update test set("a","b","c")=((select a,b,c from json_populate_record(NULL::test,'{"a":"first column","b":"second column","c":"third column"}'))) 

또한이 쿼리와 함께 UPSERT를 사용할 수도 있습니다.

insert into test select * from json_populate_record(NULL::test, '{"a":"first column","b":"column","c":"column"}') ON CONFLICT ON CONSTRAINT a_PKey DO UPDATE SET("a","b","c")=((select a,b,c from json_populate_record(NULL::test,'{"a":"first column","b":"second column","c":"third column"}'))) ; 

위 쿼리가 삽입되고 기본 키 충돌 또는 제약 조건 충돌이 발생하면 레코드가 업데이트됩니다.

관련 문제