变量

wfauudbj  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(318)

我在postgresql数据库中编写了代码:

SELECT ST_Distance(gg1, gg2) As spheroid_dist, ST_Distance(gg1, gg2, false) As sphere_dist
FROM (SELECT
   'SRID=4326;POINT(-72.1235 42.3521)'::geography as gg1,
   'SRID=4326;LINESTRING(-72.1260 42.45, -72.123 42.1546)'::geography as gg2
   ) As foo  ;

而不是'point(-72.1235 42.3521)'和linestring(-72.1260 42.45,-72.123 42.1546)'我想添加一个从表中选择的点:

SELECT ST_asText(geog) FROM punkty WHERE gid = 1

如何将所选变量添加到psql数据库的字符串中?

doinxwow

doinxwow1#

欢迎来到so。
我可能过于简化了您的问题,但只要在where子句中添加两个表或一个join(如果可能的话)就可以了。
例子:

SELECT 
  ST_Distance(t1.geog, t2.geog) As spheroid_dist, 
  ST_Distance(t1,geog, t2.geog, false) As sphere_dist
FROM 
  punkty2 t1, punkty2 t2 
WHERE t1.gid = 1 AND t2.gid = 2

相关问题