Since PostgreSQL 9.1 enum values can be added using
ALTER TYPE my_type ADD VALUE new_value;
However, trying to run this as part of a bigger script gives an error:
ALTER TYPE ... ADD cannot be executed from a function or multi-command string
This makes it a real hassle to script changes to be applied in production, because support staff have to remember that, while most scripts can be run "normally", there are a few "special" scripts that need to be opened in pgAdmin and run manually, piece by piece. I've Googled this and I understand the limitation - enum values cannot be added inside a transaction or part of a "multi-command string". That's OK. I don't need to do that. I just want to add multiple enum values and execute other, unrelated, SQL statements without having to feed Postgres one statement at a time.
In other words: I want to be able to run a single script, both from pgAdmin and from psql, that simply does the same thing that pgAdmin does when I highlight one line at a time and press F5 (run). Is there a way to do this, maybe with plpgsql?
alter type add valuecannot run in a transaction, so all you need to do is to turn off auto-commit before those statements (I don't know how to do that in pgAdmin, I don't use it)psql -f the_scriptwill work just fine.SET AUTOCOMMIT = OFFgives an error: "SET AUTOCOMMIT TO OFF is no longer supported" How does "psql -f" do it then? Does it parse the script itself and send it to the server one statement at a time?