Как взять координаты из таблицы - PullRequest
0 голосов
/ 02 апреля 2019

Мне нужно взять координаты из таблицы locations и заменить их моими данными 53.4015174, 44.967495

SELECT P.* 
    FROM PRODUCTS AS P
        LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
        LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
        LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
            WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
                ST_DWithin(M.LOCATION::geography, ST_GeogFromText('POINT(53.4015174 44.967495)'), LO.RADIUS, false)
                GROUP BY P.PRODUCT_ID, M.MERCHANT_ID

1 Ответ

1 голос
/ 05 апреля 2019

Firtly SRID задать этот запрос 4326 использовать его;

SELECT ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326);

SELECT P.* 
    FROM PRODUCTS AS P
        LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
        LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
        LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
            WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
                ST_DWithin(M.LOCATION::geography, ST_AsText(ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326))
                GROUP BY P.PRODUCT_ID, M.MERCHANT_ID
...