I have a PostGIS database containing entities A with a location (point) and entities B with an area (polygon).
I have a join table C that basically tracks who was where and I want to update it. It's a simple counter that gets incremented, no further dependencies.
It's easy enough to find out who is where:
SELECT a.id, b.id FROM a, b WHERE ST_Contains(b.poly, a.location);
But is it possible to update table C in pure SQL? It's structure is simple:
Column | Type | Modifiers
--------------+----------+----------------------------------------------------------------
id | integer | not null
a_id | integer |
b_id | integer |
counter | smallint | not null
What I want is to run a query at fixed intervalls that increments counter depending on location. However, this could be the first instance, so the matching row a_id, b_id is not guaranteed to already exist.
Possible?