2013-04-06 16 views
6

Sto usando PostgreSQL con PostGis. Sto eseguendo una ricerca come questa:SQL Query all'interno di una funzione

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

Funziona bene. Ma ora voglio prendere un valore attraverso una query. per esempio:

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

Qui data_name è una certa tabella sto usando e x negozi di alcuni valori. Ora la query interna viene trattata come una stringa e non viene restituito alcun valore.
Per favore aiuto.

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

suggerimento: come si fa a concatenare due stringhe in PostgreSQL? – muratgu

+0

|| è usato per concatenare le stringhe, ma viene comunque generato lo stesso errore – Naman

+0

@muratgu usando '||' o function: 'concat' – Houari

risposta

2

Prova questo:

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

Postgis ha una funzione ST_MakePoint che è più veloce di ST_GeomFromText.

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

Mentre @muratgu answer è generalmente la strada da percorrere, una nota minore:
Una subquery si ottiene un risultato diversoquando nessuna riga viene trovata per id = 1. Quindi si ottiene nulla in cambio (nessuna riga), invece di:

select st_geomfromtext(NULL, 432)

Se avete bisogno di un rimpiazzo:

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