0

I have code written in postgreSQL database:

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  ;

and instead of 'POINT(-72.1235 42.3521)' and LINESTRING(-72.1260 42.45, -72.123 42.1546)' I want to add a point which is selected from table:

SELECT ST_asText(geog) FROM punkty WHERE gid = 1

How to add a selected variable into string in psql database?

0

1 Answer 1

1

Welcome to SO.

I might be oversimplifying your question, but simply adding both tables in the where clause or a join (if possible) would do it.

Example:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.