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

后端 未结 2 1386
眼角桃花
眼角桃花 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条回答
  •  旧时难觅i
    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
      ...
    

提交回复
热议问题