【问题标题】:Variable in string PostgreSQL字符串 PostgreSQL 中的变量
【发布时间】:2020-09-26 15:20:50
【问题描述】:

我在 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 数据库中将选中的变量添加到字符串中?

【问题讨论】:

  • 查询成功了吗?

标签: c# sql postgresql postgis psql


【解决方案1】:

欢迎来到 SO。

我可能过于简单化了您的问题,但只需在 where 子句中添加两个表或加入(如果可能)即可。

例子:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 2013-03-30
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    相关资源
    最近更新 更多