2017-12-19 1 views
-1

로 변환됩니다 난 다음 파이썬 저장 기능을 가지고 :JSON 인수는 문자열

SELECT test_py_json('[[84160, 84285]]'::json); 

그것을 : 나는 JSON의 arguemnt으로 호출

CREATE or replace FUNCTION test_py_json(
    segments json 
) RETURNS text 
AS ' 

return type(segments) 
' 
LANGUAGE plpythonu; 
` 

<type 'str'> 

json 인수가 문자열로 변환됩니다.

이 변환을 피할 수있는 방법이 있습니까?

+0

ast Helpers: 아직 해커 그냥 노력하고 있습니다, 참조 http://www.postgresql-archive.org/Jsonb-transform-for-pl-python-td5989185.html – klin

답변

0

사용이

create or replace function test_py_json(segments json) 
returns text 
as $$ 
    import ast 
    js = ast.literal_eval(segments); 
    return type(js) 
$$ 
language plpython3u; 

select test_py_json('[[84160, 84285]]'::json), test_py_json('{"key": "value"}'::json); 

    test_py_json | test_py_json 
----------------+---------------- 
<class 'list'> | <class 'dict'> 
(1 row)