Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qSosb-007QZU-Dj for pgsql-general@arkaria.postgresql.org; Mon, 07 Aug 2023 01:17:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qSosY-005fxA-W7 for pgsql-general@arkaria.postgresql.org; Mon, 07 Aug 2023 01:17:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qSosY-005fx1-Ax for pgsql-general@lists.postgresql.org; Mon, 07 Aug 2023 01:17:50 +0000 Received: from mout.perfora.net ([74.208.4.194]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qSosR-000vtF-IE for pgsql-general@lists.postgresql.org; Mon, 07 Aug 2023 01:17:49 +0000 Received: from [192.168.1.17] ([72.94.51.172]) by mrelay.perfora.net (mreueus003 [74.208.5.2]) with ESMTPSA (Nemesis) id 0LzdUS-1ph5jL0j58-014hy1 for ; Mon, 07 Aug 2023 03:17:41 +0200 To: PostgreSQL Users Mailing List From: H Subject: Dropping all tables in a database Message-ID: Date: Sun, 6 Aug 2023 21:17:40 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Provags-ID: V03:K1:YtkOz26aVuPxmbayn1Tu81kSSqx1lP/4hgdh2W8v3H4FrkSezNG IW7PQWCCclebEEDzjSPfwr1H1mjK+UCBbQhZ6i2LPiCpLfgfcgPS1dEj4C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kOm55Nw== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I am running PostgreSQL  13.11 and tried to drop all tables in a database without dropping the database or schema. After logging in as the correct user, the following SQL statement does not work: SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;' FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'xxx'; The above statement does not drop any tables, nor are there any error messages. SELECT * FROM pg_tables; The above shows all tables are still present in the database. Dropping individual tables works fine but since I need to drop all tables in the database in a develop environment, this is not workable. I had to resort to the following: -- turn off headers: \t SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;' FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'livraddarpaket'; \g out.tmp \i out.tmp The SQL statements above run fine. Is there some setting I have to change in the database to have the first SQL statement to work or have I run into a possible bug?