Here’s how I can do it when MySQL is the backend,
cursor.execute('show tables')
rows = cursor.fetchall()
for row in rows:
cursor.execute('drop table %s; ' % row[0])
But how can I do it when postgresql is the backend?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
select * from pg_tables;get get a list of tables, although you probably want to excludewhere schemaname <> 'pg_catalog'…Based on another one of your recent questions, if you’re trying to just drop all your django stuff, but don’t have permission to drop the DB, can you just DROP the SCHEMA that Django has everything in?
Also on your drop, use CASCADE.
EDIT: Can you
select * from information_schema.tables;?EDIT: Your column should be
row[2]instead ofrow[0]and you need to specify which schema to look at with aWHERE schemaname = 'my_django_schema_here'clause.EDIT: Or just
SELECT table_name from pg_tables where schemaname = 'my_django_schema_here';androw[0]