使用 PostgreSQL-9.1 和 PostGIS 2.0.1,在执行包含返回多列的子查询的 SELECT 查询时,我收到错误消息subquery must return only one column
。
如何修改查询/子查询以返回多列?
询问
SELECT l.id, l.lat, l.lng, l.geom,
(SELECT g.id, g.lat, g.lng, ST_Distance(l.geom, g.geom)
FROM stage.dogs as g
LIMIT 1)
FROM stage.users As l
完整查询
SELECT l.id, l.lat, l.lng, l.geom,
g.id, g.lat, g.lng, ST_Distance(l.geom, g.geom)
FROM stage.users As l
CROSS JOIN (SELECT *
FROM stage.dogs as g
ORDER BY g.geom <-> l.geom
LIMIT 1) as g
错误
ERROR: invalid reference to FROM-clause entry for table "l"
SQL state: 42P01
Hint: There is an entry for table "l", but it cannot be referenced from this part of the query.