tags:

views:

43

answers:

1

How can I delete all tables in postgresql, working from the command line?

I don't want to drop the database itself - just all tables and all the data in them.

Thanks.

+1  A: 

You can write a query to generate a SQL script like this:

select 'drop table ' || tablename || ' cascade;' from pg_tables;

Or:

select 'drop table if exists ' || tablename || ' cascade;' from pg_tables;

In case some tables are automatically dropped due to cascade option in a previous sentence.

And then run it.

Glorious COPY+PASTE will also work.

Pablo Santa Cruz
I think you meant: You can write a query like this... ...And then run the output of the query
Vinko Vrsalovic
True. That's what I meant. :-)
Pablo Santa Cruz