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

后端 未结 2 1381
眼角桃花
眼角桃花 2021-01-24 15:34

so from this code:

from dosql import *
import cgi
import simplejson as json

def index(req, userID):
    userID = cgi.escape(userID)

    get = doSql()
    rec =         


        
相关标签:
2条回答
  • 2021-01-24 15:53

    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
      ...
    
    0 讨论(0)
  • 2021-01-24 15:54

    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]]
    
    0 讨论(0)
提交回复
热议问题