Dropping a group of schemas with similar name patterns 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.
This query on the system catalog creates the necessary DDL script:
SELECT string_agg(format('DROP SCHEMA %I CASCADE;', nspname), E'\n')
FROM   pg_namespace
WHERE  nspname LIKE 'ceu_shard_test_merge_%';

Note the use of format() to escape identifiers if necessary.
format() requires PostgreSQL 9.1+.
Replace with quote_ident() in older versions.
string_agg() requires PostgreSQL 9.0+.
Replace with array_to_string(array_agg(...), E'\n') in older versions.
For Postgres 8.4, that would be:
SELECT array_to_string(
          array_agg('DROP SCHEMA ' || quote_ident(nspname) || ' CASCADE;')
        , E'\n')
FROM ...

Returns:
DROP SCHEMA ceu_shard_test_merge_1 CASCADE;
DROP SCHEMA ceu_shard_test_merge_2 CASCADE;
...

Which you can inspect before executing.
You can put it all into a DO command for automatic execution or create a function for repeated use. Consider this closely related answer for a complete code example:

Bug in PL/pgSQL function creation

Or this related answer on SO.
Output in psql
In response to @Stew's comment: To display unadorned text as result in psql you can use the \pset meta-command:
\pset format unaligned
\pset tuples_only

Or use the short commands \x \a