1.)
LISTEN and NOTIFY would be the best solution, but my driver (php pdo driver) sadly does not support that, and I think it never will, because this is a postgres specific feature.
2.)
I think with my driver the only option to use temporary tables. I created the following functions for that:
init
CREATE FUNCTION policy_change_provide_store ()
RETURNS VOID
AS
$BODY$
BEGIN
CREATE TEMPORARY TABLE policy_change (
user_id INT4
);
EXCEPTION WHEN duplicate_table THEN
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
update
CREATE FUNCTION policy_change_update (
IN user_ids INT4 []
)
RETURNS VOID
AS
$BODY$
BEGIN
PERFORM policy_change_provide_store();
INSERT INTO policy_change
SELECT inserted_user_id FROM unnest(user_ids) AS inserted_user_id
WHERE NOT EXISTS(SELECT 1 FROM policy_change WHERE user_id = inserted_user_id);
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
read
CREATE FUNCTION user_read_all_by_policy_change ()
RETURNS TABLE (
user_id INT4
)
AS
$BODY$
BEGIN
PERFORM policy_change_provide_store();
RETURN QUERY
SELECT policy_change.user_id FROM policy_change ORDER BY policy_change.user_id DESC;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
So I update the policy change data from my postgres functions with policy_change_update(user_ids)
and read that from the http server with user_read_all_by_policy_change()
. Ye, this is ugly, but it works well. If you got a better solution please let me know!