例如,我用下面的函数转换rows
成json
中PostgreSQL 9.2
select row_to_json(row(productid, product)) from gtab04;
这将返回以下结果
row_to_json
---------------
{"f1":3029,"f2":"DIBIZIDE M TAB"}
{"f1":3026,"f2":"MELMET 1000 SR TAB"}
{"f1":2715,"f2":"GLUCORED FORTE"}
{"f1":3377,"f2":"AZINDICA 500 TAB"}
要解决此问题,我们必须创建一个行类型并将该行强制转换为该类型,或者使用子查询。子查询通常会更容易。
select row_to_json(t)
from (
select productid, product from gtab04
) t
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句