-
Notifications
You must be signed in to change notification settings - Fork 7
/
queries.sql
42 lines (39 loc) · 1.03 KB
/
queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
SELECT
users.*,
ST_DistanceSphere(
ST_SetSRID(
ST_MakePoint(
(users.coord->'coordinates'->>0)::float,
(users.coord->'coordinates'->>1)::float
), 4326
),
ST_SetSRID(ST_MakePoint(-46.6333, -23.5505), 4326)
) AS distance
FROM
users;
SELECT
users.*,
ST_DistanceSphere(
ST_SetSRID(
ST_MakePoint(
(users.coord->'coordinates'->>0)::float,
(users.coord->'coordinates'->>1)::float
), 4326
),
ST_SetSRID(ST_MakePoint(-46.6333, -23.5505), 4326)
) AS distance
FROM
users
WHERE
users.coord->'coordinates'->>0 IS NOT NULL
AND users.coord->'coordinates'->>1 IS NOT NULL
ORDER BY
ST_DistanceSphere(
ST_SetSRID(
ST_MakePoint(
(users.coord->'coordinates'->>0)::float,
(users.coord->'coordinates'->>1)::float
), 4326
),
ST_SetSRID(ST_MakePoint(-46.6333, -23.5505), 4326)
) ASC;