How to return two columns with function

后端 未结 1 474
礼貌的吻别
礼貌的吻别 2020-12-07 06:27

I want to return 2 values with my SQL function:

CREATE OR REPLACE FUNCTION get_avg_prices(...)
  RETURNS table(avg_sale_price decimal, avg_rent_price decimal         


        
相关标签:
1条回答
  • 2020-12-07 06:43

    Table functions (functions defined as returns table or returns setof) need to be used in the from clause like a table.

    So you need to use:

    select * 
    from get_avg_prices(...);
    

    Only scalar functions (functions which return only a single value, e.g. a number) should be put into the select list.

    0 讨论(0)
提交回复
热议问题