I am trying to return the count of overlapping polygons. The problem is that it complains about my "$1" signs:
Error is "SQL state: 42601", syntax error at "$1".
Why is this? I'm a total beginner here and I can't find the solution online, other than that parameters is referenced to with $
sign.
CREATE OR REPLACE FUNCTION any_overlap (x text)
RETURNS integer AS $$
DECLARE amount INTEGER;
BEGIN
SELECT COUNT(*) INTO amount FROM $1 a
INNER JOIN $1 b ON
(a.polygon && b.polygon AND ST_Relate(a.polygon, b.polygon, '2********'))
WHERE a.ctid != b.ctid;
RETURN amount AS id;
END; $$ LANGUAGE plpgsql;
x
supposed to be a table name? You're passing it as atext
value, which makes yourSELECT
statements nonsensical