Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all table without dropping database in postgres in django dbshell in one command?

Tags:

I tried this ..

 select 'drop table if exists "' || tablename || '" cascade;' 
from pg_tables
 where schemaname = 'public';

but doesn't seems to work out for one command?

like image 381
Irshadmi4 Avatar asked Nov 16 '13 10:11

Irshadmi4


People also ask

How do I delete all tables in PostgreSQL?

How to drop all tables in PostgreSQL? 2 From TablePlus GUI: You can select all the available tables from the right sidebar, right click and choose Delete.. , or press Delete key to drop all. Don't forget to commit changes to the server (Cmd + S) after doing so.

How delete all data from PostgreSQL database?

First, specify the table from which you want to delete data in the DELETE FROM clause. Second, specify which rows to delete by using the condition in the WHERE clause. The WHERE clause is optional. However, if you omit it, the DELETE statement will delete all rows in the table.

How do I permanently delete a table in PostgreSQL?

PostgreSQL has a DROP TABLE statement that is used to remove an existing table or tables from the database. Syntax: DROP TABLE [IF EXISTS] table_name [CASCADE | RESTRICT]; Let's analyze the above syntax: We specify the table name after the DROP TABLE keyword to remove the table permanently from the database.


1 Answers

If all of your tables are in a single schema, this approach could work (below code assumes that the name of your schema is 'public')

drop schema public cascade;
create schema public;

Drop all tables in PostgreSQL?

see above link for more answers

like image 98
Haji Avatar answered Sep 28 '22 12:09

Haji