2016-09-07 7 views
1

에 의해 얻을 jsonb하는 것은 가능 포스트 그레스이 그런 짓을하는 것입니다 : the operator #>포스트 그레스 동적 경로

do $$ 
declare 
    v_key text; 
    v_json jsonb; 
begin 
    v_key := 'id'; 
    v_json := jsonb_build_object(
    'id', jsonb_build_object('nest_id',1) 
); 
    raise notice '%', v_json #> '{'||v_key||'}'->>'nest_id'; 
end$$ 

ERROR: operator does not exist: jsonb #> text
No operator matches the given name and argument type(s). You might need to add explicit type casts.

+1

''{ '|| v_key ||'} ':: jsonb' –

답변

0

오른쪽 피연산자 유형이 텍스트의 배열입니다. array[...] 표기법을 사용

raise notice '%', v_json #> array[v_key]->>'nest_id'; 

또는 형식 배열 리터럴 :

raise notice '%', v_json #> ('{'||v_key||'}')::text[]->>'nest_id'; 
+0

너무 감사합니다! 그것은 작동합니다! –