我参考了文档中的示例,它运行良好:
select * from json_populate_record(null::x, '{"a":1,"b":2}')
Run Code Online (Sandbox Code Playgroud)
但是我自己构建的 JSON 简化类似于这样没有工作:-(
-- p_some_num of type int
select * from json_populate_record( null:my_record_type, '{"a":'||p_some_num||'',"b":2}' )
Run Code Online (Sandbox Code Playgroud)
导致:
ERROR: function json_populate_record(my_record_type, text) does not exist
Run Code Online (Sandbox Code Playgroud)
我应该更仔细地阅读,并且不知道示例中隐含的text
转换json
。经过一番摆弄错误之后,当然可以进行以下操作:
select * from json_populate_record(
null:my_record_type, ('{"a":'||p_some_num||'',"b":2}')::json )
Run Code Online (Sandbox Code Playgroud)