如何在postgresql中使用row_to_json时从返回的列中删除f1?

时间:2016-12-06 09:05:10

标签: sql json postgresql postgresql-9.1

我正在使用row_to_json将列转换为json。 这是我的疑问:

 Select row_to_json(row(func1('cust_1')));

注意func1是一个sql函数,它接受一个varchar并返回3个浮点数

此查询正在返回:

{"f1":{"col1":0,"col2":0,"col3":0}}

我想要的是f1中的对象,我希望查询只返回:

{"col1":0,"col2":0,"col3":0}

我该怎么做? 谢谢

1 个答案:

答案 0 :(得分:2)

只需Get JSON object field as text

Select row_to_json(row(func1('cust_1')))->>'f1';