如何从一个函数中选择多个值到单独的列中?

时间:2019-04-03 22:08:32

标签: sql postgresql set-returning-functions

这是我的查询

react-select

返回

SELECT
    *
FROM (
    SELECT 
        getlatlng("geom")
    FROM
        mytable
) AS subquery;

我想写

(-121.9,36.4)
(-117.1,32.9)
(-121.9,36.5)
(-71.2,42.6)

让它返回

SELECT
    subquery.lat, subquery.lon 
FROM (
    SELECT 
        getlatlng("mygeom")
    FROM
        mytable
) AS subquery;

以下是函数的相关位。

lat  | lon
-------------
36.4 | -121.9
32.9 | -117.1
36.5 | -121.9
42.6 | -71.2

1 个答案:

答案 0 :(得分:2)

尝试:

SELECT (p).longitude, (p).latitude FROM (
    SELECT getlatlng("mygeom") p 
      FROM mytable
) subquery

函数的OUT参数定义了返回记录的列。

Example fiddle