I have this problem, I don't know if I should make the functions on Postgresql DB with plpgsql or if I should make it inside a class on python/java whatever language programming might work.
My boss asked me why I was writing the functions on plpgsql and not on python and I coulnd't give him a reliable answer of why it was better.
I have google it and I couldn't find any information about this. The only thing that I can imagine about doing the function on plpgsql is that if I change of programming language the only thing that I would need to do is to call the function and not rewriting it on the new language.
This is an example of a plpgsql that I write with the help of a stackoverflow member, should I rewrite it in a python class or leave it inside the db as a function and just call the function from a python class?
CREATE OR REPLACE FUNCTION createid(idslist varchar[], objecttype varchar)
RETURNS TABLE(original_id varchar, new_id varchar) as
$$
declare
l_prefix text;
BEGIN
IF LOWER(objectType) = 'global' THEN
l_prefix := 'GID';
ELSE
l_prefix := 'ORG';
END IF;
RETURN QUERY
INSERT INTO idstable(original_id, new_id)
select t.x, l_prefix||nextval('mapSquema.globalid')::TEXT
from unnest(idslist) as t(x)
returning *
END;
$$ LANGUAGE plpgsql;