How can I run a
function a on master only?
I don't want to connect directly to my master server, because the master server might change.
Or can I change my function to work on this setup? Because at the moment using the below function, will say that the server is read-only?
ERROR: cannot execute SELECT in a read-only transaction CREATE FUNCTION..... WITH sel AS ( SELECT id FROM univ.domains WHERE name = domain_name ) , ins AS ( INSERT INTO univ.domains (name) SELECT domain_name WHERE NOT EXISTS (SELECT 1 FROM sel) RETURNING id ) SELECT id FROM sel NATURAL FULL OUTER JOIN ins INTO domain_id; ... LANGUAGE plpgsql
Also tried adding
SET TRANSACTION READ WRITE; after
begin and got:
cannot set transaction read-write mode inside a read-only transaction