I have a Postgres server with 2 databases on it, db1 and db2. The second one, db2 has lots of tables in it.
I want to keep both of these databases, but would like to "truncate" (delete all tables from) db2. My best attempt thus far is:
db2=# \c db1
You are now connected to database "db1" as user "postgres".
db1=# SELECT 'drop table if exists "' || tablename || '" cascade;' as pg_drop FROM pg_tables WHERE schemaname='db2';
postgres=# \c db2
You are now connected to database "db2" as user "postgres".
db2=# \dt
 public | agent_machines                | table | muyapp_admin
 public | agent_message_queue           | table | muyapp_admin
 public | agent_pools                   | table | muyapp_admin
 public | alerts                        | table | muyapp_admin
 ...
And clearly, its not working, since there are still tables in db2 after I do the SELECT.
Can anyone spot where I'm going awry?
