Tuple to List - Python / PostgreSQL return type of SETOF Record

*爱你&永不变心* 提交于 2019-12-02 05:40:56

SELECT get_progressrecord(ID) will return a single column of type record.

SELECT * FROM get_progressrecord(ID) will return multiple columns (matching your out params).

As an aside, the fact that your output fields have no names might make your function a little difficult to work with. There's also an alternative syntax for RETURNS SETOF RECORD which I find easier:

CREATE OR REPLACE FUNCTION get_progressrecord(int)
  RETURNS TABLE(
    height decimal(5,2),
    weight decimal(5,2),
    bmi decimal(4,2),
    healthStatus text,
    age int,
    changePercentage decimal(4,2)
  ) AS
  ...

You can use map function for this aim :

Demo :

>>> tuple_list=[(300.00,30.00,3.33,'underweight',21,0.00),(300.00,30.00,3.33,'underweight',21,0.00)]
>>> map(list,tuple_list)
[[300.0, 30.0, 3.33, 'underweight', 21, 0.0], [300.0, 30.0, 3.33, 'underweight', 21, 0.0]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!