2017-12-19 15 views
-1

に変換されるI次のPython保存された機能を持っている: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) 
関連する問題