1
SELECT ST_Distance(USER_POLY,  NEW_LOC) as dist 
FROM (
  SELECT (select ST_transform(ST_SetSRID(ST_MakePoint( 11.61594943945313, 48.12707189053979),4326),3857)) AS  RES_LOC,   
         (SELECT ST_Transform((select u.poly 
                               FROM USERS u 
                               WHERE u.user_id =  '83b71cee-e9b8-46cb-9bee-6d7ee6f44cc6'), 3857)) AS  USER_POLY
) AS foo

I have tried the query in the cli and it worked once I removed the as dist but using node I get the error: syntax error at or near "SELECT", I tried casting but to no avail.

user42141
  • 33
  • 4
  • 1
    Why do you use "select ST_transform" instead of just "ST_transform" ? And I think you could rewrite the query in such a way that you don't the subquery at all. Maybe this is something node can't handle – Frank Heikens Nov 25 '22 at 11:19
  • @FrankHeikens Nodejs doesn't do any syntax checks – Bergi Nov 25 '22 at 11:24
  • 2
    This query can be written without any sub-queries at all: https://pastebin.com/fYgrA30i –  Nov 25 '22 at 11:24
  • Please post the nodejs code you were running that led to the error – Bergi Nov 25 '22 at 11:26
  • @a_horse_with_no_name you are a life saver and make me much more enthusiastic about horses! TY. – user42141 Nov 25 '22 at 12:53
  • On a side note, don't compute distances using `3857` as this CRS highly distort them. You can use [`ST_DistanceSphere`](https://postgis.net/docs/ST_DistanceSphere.html) on the geometries in `4326` – JGH Nov 25 '22 at 13:04
  • Are `NEW_LOC` and `RES_LOC` supposed to be the same? – SebDieBln Nov 25 '22 at 13:05

0 Answers0