Operation on mixed SRID geometries error

geometrypostgispostgresqlquerysrid

I have two tables flickr_edin and temmpat.

temppat was created using:

CREATE TABLE temppat (id serial, geom geometry);
INSERT INTO temppat (geom) VALUES (ST_GeomFromText('POINT (326253.33 674110.63)'));

flickr_edin contains columns id, date_taken, user and geom.

I want to find out how many photos have been taken within 200m of this location in temmpat for each day of the week.

This is my query:

SELECT COUNT(*) as count,EXTRACT('dow' FROM date_taken) as dow
FROM flickr_edin a JOIN temppat b ON ST_WITHIN(a.geom,ST_BUFFER(b.geom,200))
GROUP BY dow;

I get this error:

ERROR: contains: Operation on mixed SRID geometries (Polygon, 0) !=
(Point, 27700) SQL state: XX000

Best Answer

An inline SQL test to demonstrate what goes wrong and how to fix the problem.

select ST_Within(
ST_GeomFromText('POINT (326253.33 674110.63)'),
ST_Buffer(ST_GeomFromText('POINT (326253.33 674110.63)',27700),10));

ERROR:  contains: Operation on mixed SRID geometries
(Polygon, 27700) != (Point, 0)
SQL state: XX000


select ST_Within(
ST_GeomFromText('POINT (326253.33 674110.63)',27700),
ST_Buffer(ST_GeomFromText('POINT (326253.33 674110.63)',27700),10));

true