Postgres SELECT with multiple select as


Я пытаюсь использовать выходные данные из двух операторов SELECT в функции PostGIS.

Каков правильный синтаксис для этого? Я получаю синтаксическую ошибку во втором операторе SELECT или рядом с ним.

SELECT ST_Split(tracks, roads)
FROM
(
    SELECT * FROM (SELECT ST_Buffer(road_geom,50) FROM table1 WHERE a = '' AND b = '') as roads,
    SELECT * FROM (SELECT the_geom FROM table2 WHERE c = '' AND d = '') as tracks

)

Вывод ошибок:

 ERROR:  syntax error at or near "SELECT"
 LINE 5:  SELECT * FROM (SELECT the_geom FROM table2...
     ^
********** Error **********
ERROR: syntax error at or near "SELECT"
SQL state: 42601
Character: 178

Спасибо!

1 2

1 ответ:

Демонстрация одного метода использования CTE:

WITH    roads as (SELECT ST_Buffer(road_geom,50) as road FROM table1 WHERE a = '' AND b = ''),
        tracks as (SELECT the_geom as track FROM table2 WHERE c = '' AND d = '')
SELECT ST_Split( (select track from tracks), (select road from roads) );

Docs at http://www.postgresql.org/docs/current/static/queries-with.html