So, I have a table which describes positions of some entities in space(for simplicity in one dimension, original problem is related )
CREATE TABLE positions(
id VARCHAR (32) UNIQUE NOT NULL,
position VARCHAR (50) NOT NULL
);
And I create a trigger which notifies on every update
CREATE TRIGGER position_trigger AFTER UPDATE ON positions
FOR EACH ROW
EXECUTE PROCEDURE notify_position();
and a function:
CREATE FUNCTION notify_position() RETURNS trigger AS $$
DECLARE
BEGIN
PERFORM pg_notify(
'positions',
TG_TABLE_NAME || ',id,' || NEW.id || ',position,' || NEW.position
);
RETURN new;
END;
$$ LANGUAGE plpgsql;
how can I change the function to notify only when there are few entities in the same position.
e.g. consider a table after update
id |positions
-------------
id1 |10
id2 |10
id3 |11
I need to call notify with a string 'id1,id2'
Probably, I need to select somehow all the entities which have the same position as updated one and create a list of them(a string which contains comma-separated ids). How can I do that?