I have a lookup table that holds a column of sources (from various hardcoded campaigns captured through a webservice API I created) and the respective brands that should be associated with them. This is so I can give a brand to records where brand is null - so that they can be welcomed with a certain template through a marketing automation tool.
I'm eventually deprecating this API and replacing it with one where brand is required, but in the meantime I have to craft a temporary solution until I give all my brand teams time to change their API calls.
I wrote this function:
CREATE OR REPLACE FUNCTION public.brand_lookup(IN i_brand TEXT )
RETURNS SETOF RECORD VOLATILE AS
$$
BEGIN
RETURN QUERY
UPDATE subscriber
SET brand = (SELECT brand FROM brand_translation
WHERE source = subscriber.source);
END;
$$
LANGUAGE plpgsql;
And a trigger to fire the function when a record is inserted:
CREATE TRIGGER brand_translation
AFTER INSERT ON subscriber
FOR EACH ROW EXECUTE PROCEDURE public.brand_lookup();
But my trigger comes back with an error that "ERROR: function public.brand_lookup() does not exist" (but it created successfully)". Besides the fact that my trigger doesn't see my function, will that function do what I'm intending? I'm fairly noob at functions (as you can probably tell).