This doesn't answer my question.
I have found a query like this for searching objects in a circle.
SELECT id, ST_X(location),ST_Y(location), state
FROM (
SELECT id, location, state, r,
units * DEGREES( ACOS(
COS(RADIANS(latpoint))
* COS(RADIANS(ST_X(location)))
* COS(RADIANS(longpoint) - RADIANS(ST_Y(location)))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(ST_X(location))))) AS distance
FROM fountains
JOIN (
SELECT 13.1 AS latpoint, 2 AS longpoint,
1000 AS r, 111.045 AS units
) AS p ON (1=1)
WHERE MbrContains(ST_GeomFromText(
CONCAT('LINESTRING(',
latpoint-(r/units),' ',
longpoint-(r /(units* COS(RADIANS(latpoint)))),
',',
latpoint+(r/units) ,' ',
longpoint+(r /(units * COS(RADIANS(latpoint)))),
')')), location)
) AS d
WHERe d.distance <= d.r HAVING d.state="faulty"
ORDER BY d.distance ASC;
This is the result on my database:
id ST_X(location) ST_Y(location) state
2 13.1 2.1 usable
1 13 2 faulty
3 13.2 2.2 usable
5 13.3 2.3 usable
6 12.9 2.3 usable
How to add a clause to add a condition on the result? Like if I want to have only the records with the column state=="usable"?
I see also that if I go on localhost:xxxx and enter in my db, with a where clause or an having clause I can do it, but with my GO lang server, I cant.