Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: drop table ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 3376 of 3799
Post > Topic >>

Re: drop table where tableName like 'backup_2007%' ?

by tgl@[EMAIL PROTECTED] (Tom Lane) Mar 31, 2008 at 11:55 AM

Emi Lu <emilu@[EMAIL PROTECTED]
> writes:
> Is there a command to drop tables whose name begins a specific string?

No.  The standard answer to this type of problem is to write a little
plpgsql function that scans the appropriate catalog and issues commands
constructed with EXECUTE.

	for r in select relname from pg_class where relname like 'backup_2007%'
	loop
		execute 'DROP TABLE ' || quote_ident(r);
	end loop;

Note that the above is overly simplistic --- it doesn't pay attention
to schemas, for example.

Some people prefer to just print out the constructed commands into a
file, so they can eyeball them before actually executing them.

			regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 3 Posts in Topic:
drop table where tableName like 'backup_2007%' ?
emilu@[EMAIL PROTECTED]   2008-03-31 10:48:27 
Re: drop table where tableName like 'backup_2007%' ?
tgl@[EMAIL PROTECTED] (T  2008-03-31 11:55:14 
Re: drop table where tableName like 'backup_2007%' ?
dev@[EMAIL PROTECTED] (R  2008-03-31 17:27:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 22:34:57 CST 2008.