postgresql Postgres SELECT 多选为

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19595377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:09:47  来源:igfitidea点击:

Postgres SELECT with multiple select as

postgresqlselectpostgis

提问by Matt

I'm trying to use the output from two SELECT statements in a PostGIS function.

我正在尝试在 PostGIS 函数中使用两个 SELECT 语句的输出。

What is the correct syntax for doing this? I'm getting a syntax error at or near the second SELECT statement.

这样做的正确语法是什么?我在第二个 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 output:

错误输出:

 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

Thanks!

谢谢!

回答by bma

Demonstrating one method of using a CTE:

演示使用 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

http://www.postgresql.org/docs/current/static/queries-with.html 上的文档