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.