In a customer project I have to setup a database from a
Makefile. Part of my problem: on Windows the installer may or may not install
template1, therefore in consequence this language may or may not be activated in every new database. But that’s not predictable. This problem can appear on different Linux/Unix distributions too.
In contrary to some other opinions in
#postgresql, I dislike filtering error messages and I prefer clean solutions.
CREATE LANGUAGE will spit an error message, if the language is already activated. A
IF NOT EXIST option is not available. I need a workaround:
First I create a helper function which will install the language, if executed. This step is needed because I cannot put the
CREATE LANGUAGE statement into the
CASE clause. The next statement looks into
plpgsql is already installed - if yes, just a message is returned - if no, the previously created function is called. Last but not least the function is dropped, it’s not needed anymore.
I can execute this code from my
Makefile and expect to get no error message even if the language already exist.