Random stuff, testing things, and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
527 B

CREATE OR REPLACE FUNCTION notify_channel()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
DECLARE
target_channel TEXT;
BEGIN
SELECT channel_name
INTO target_channel
FROM targets
WHERE level_1 = NEW.level_1
AND level_2 = NEW.level_2;
if found then
SELECT pg_notify(target_channel, NEW.payload);
UPDATE commands
SET channel_name = channel_name, channel_failure = false
WHERE id = NEW.id;
else
UPDATE commands
SET channel_failure = true
WHERE id = NEW.id;
end if;
END;
$$;