Software14
Software14

Reputation: 179

SQL : combine 2 statements with 2 SELECT

How can I combine these 2 SQL statement into a one?

I would like to replace the value shape here:

SELECT path[1] AS number, st_x(geom), st_y(geom) 
FROM st_dumppoints(shape)

by this :

SELECT shape 
FROM tableA 
WHERE id = 'test'

Something like this:

SELECT path[1] AS number, st_x(geom), st_y(geom) 
FROM st_dumppoints(SELECT shape FROM tableA WHERE id = 'test')

Upvotes: 1

Views: 49

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246523

Just add an extra pair of parentheses around the subselect. Syntactically, a subquery needs parentheses, and the function invocation too, so you end up with

FROM st_dumppoints((SELECT shape FROM tableA WHERE id = 'test'))

Note that the statement will cause an error if the subquery returns more than one row.

Upvotes: 1

Related Questions