Re: Destroying all exisitng tables in database

Поиск
Список
Период
Сортировка
От Hans Peter Wiedau
Тема Re: Destroying all exisitng tables in database
Дата
Msg-id 20050419132805.GA5860@entoron.wiedau.de
обсуждение исходный текст
Ответ на Destroying all exisitng tables in database  ("Lim, Terrin" <terrin.lim@imperial.ac.uk>)
Список pgsql-admin
On Wed, Apr 13, 2005 at 04:20:40PM +0100, Lim, Terrin wrote:
> I'm trying to drop all tables in a database but I can't use DROP dbname
> as I don't have permission rights to do so. I also can't manually delete
> all the tables cause there are about 200 tables. How do i go about this?
> Thanks.

Here is a little PL/pgSQL sniplet, I used to delete all tables from
schema public:

----- snip-snap -----

CREATE OR REPLACE FUNCTION dropit() RETURNS integer AS'
DECLARE
    numberoftables integer := 0;
    tabletodrop RECORD;
BEGIN
    FOR tabletodrop IN SELECT tablename from pg_tables where
schemaname=''public'' LOOP
        numberoftables := numberoftables + 1;
        RAISE NOTICE ''Droping table %'', tabletodrop.tablename;
        EXECUTE ''DROP TABLE public.''
            || tabletodrop.tablename;
    END LOOP;
    RETURN numberoftables;
END;
' LANGUAGE plpgsql;

----- snip-snap -----

You execute it by "select dropit();" on the psql commandline.

But be warned, it will drop _all_ tables in the used schema.

cu,

Hans Peter

--
 /////    Quelltext AG -- Professional Software Services
//   //   Hans Peter Wiedau <hpw-nl@quelltext.com>, CEO
//   //   Ostenhellweg 31, 44135 Dortmund, Germany
//  \\/   fon +49 231 9503750, fax +49 231 9503751
 ////\\   Web http://www.quelltext.com

В списке pgsql-admin по дате отправления:

Предыдущее
От: Wim Bertels
Дата:
Сообщение: Re: brute force attacking the password
Следующее
От: Dextra - Gustavo Bartz Guedes
Дата:
Сообщение: PAM authentication