2013-04-06 56 views
6

我在PostGis中使用PostgreSQL。我正在执行这样的查询:函数内部的SQL查询

select st_geomfromtext('point(22 232)',432) 

它工作正常。但是现在我想通过查询来获取价值。例如:

select st_geomfromtext('point((select x from data_name where id=1) 232)' , 432) 

这里data_name是一些表我使用和x商店某些数值。现在,内部查询被视为字符串,并且不返回任何值。
请帮忙。

ERROR: syntax error at or near "select" 
+0

提示:你怎么连接两个字符串中PostgreSQL的? – muratgu 2013-04-06 21:15:17

+0

||用于连接字符串,但仍会抛出相同的错误 – Naman 2013-04-06 21:24:02

+0

@ muratgu使用'||'或函数:'concat' – Houari 2013-04-06 21:24:05

回答

2

试试这个:

select st_geomfromtext('point(' || x || ' 232)', 432) from data_name where id=1 
0

POSTGIS具有功能ST_MakePointST_GeomFromText更快。

select ST_SetSRID(ST_MakePoint(x),432) from data_name where id=1; 
0

虽然@muratgu answer一般要走的路,一个小小的提示:
子查询让你一个不同的结果时没有行发现id = 1。然后你得到任何回报(没有行),而不是:

select st_geomfromtext(NULL, 432)

如果你需要一个简易替换:

select st_geomfromtext('point(' 
         || (select x from data_name where id=1) 
         || ' 232)' , 432)