Consider a situation where one need to perform a bunch of essentially identical operations, with the only variable being the name of some object.
In my case, I need to drop some schemas, all of the form ceu_shard_test_merge_*
, to use shell globbing terminology. So, conceptually, this can be written as
DROP SCHEMA ceu_shard_test_merge_* CASCADE;
by analogy with a Unix shell.
Of course this command doesn't work, so how can one do this with a single command? My understanding is that this cannot be done portably. I'm using PostgreSQL 8.4, but methods for more recent versions of PG are fine too.
It would be nice if the solution had a dry run or dummy option, so one could see what commands were going to be run before actually running them. Perhaps a way to just print the commands?
Also, an indication of how to deal with more general patterns than the example given would be nice.