Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 1A1BB2E009A for ; Mon, 31 Mar 2008 12:55:31 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36841-04-3 for ; Mon, 31 Mar 2008 12:55:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 17C842E0095 for ; Mon, 31 Mar 2008 12:55:28 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m2VFtE6B028894; Mon, 31 Mar 2008 11:55:14 -0400 (EDT) To: emilu@encs.concordia.ca cc: pgsql-sql@postgresql.org Subject: Re: drop table where tableName like 'backup_2007%' ? In-reply-to: <47F0F9BB.3060706@encs.concordia.ca> References: <47F0F9BB.3060706@encs.concordia.ca> Comments: In-reply-to Emi Lu message dated "Mon, 31 Mar 2008 10:48:27 -0400" Date: Mon, 31 Mar 2008 11:55:14 -0400 Message-ID: <28893.1206978914@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200803/209 X-Sequence-Number: 30537 Emi Lu 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