SSMS (via SMO) allows you to script it at the category (function) level. It won't allow you to specify only table valued functions.
You could also look at something like this article for using PS to automate the creation. You might be able to filter the objects being scripted by the function type (tvf, scalar, etc)
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:
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
Best Answer
To drop all functions (including aggregates) in a given schema (be careful with this!):
Postgres 11 or later
pg_proc
slightly changed:prokind
replacesproisagg
andproiswindow
- and also tags functions and the new proceduresThe schema name is case sensitive in this context.
The executing role needs to have the necessary privileges of course.
You might add
CASCADE
like demonstrated by mehmet but that will also drop depending objects, recursively - not just functions. Makes it even more dangerous. You better know exactly what you are doing.Related, with more explanation:
Postgres 10 or older