Re: Need exact SQL query to find List of Detach Partitioned Tables (Yet to be Dropped) - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Need exact SQL query to find List of Detach Partitioned Tables (Yet to be Dropped)
Date
Msg-id 389718a6-b146-40bd-be7c-1f6a427cec0c@aklaver.com
Whole thread Raw
In response to Need exact SQL query to find List of Detach Partitioned Tables (Yet to be Dropped)  (Bharani SV-forum <esteembsv-forum@yahoo.com>)
List pgsql-general
On 11/15/24 11:46, Bharani SV-forum wrote:
>   Team
> 
> Need exact SQL query to find List of Detach Partitioned Tables (Yet to 
> be Dropped)
> 
> The following is the query which i used, i am using and i found an bug 
> which is listing an newly created table (last week)

As David G. Johnston said how would you know it was formally a partition?:

https://www.postgresql.org/docs/current/sql-altertable.html

"
DETACH PARTITION partition_name [ CONCURRENTLY | FINALIZE ]

     This form detaches the specified partition of the target table. The 
detached partition continues to exist as a standalone table, but no 
longer has any ties to the table from which it was detached.

[...]
"

The only I could see this working is if you had a standard naming scheme 
for partitions and then you could do a regex search in pg_class for that 
pattern where relkind = 'r'.

> 
> SELECT relnamespace::regnamespace::text AS schema_name, relname AS 
> table_name
> FROM   pg_class c
> WHERE  NOT relispartition  -- !
> AND    relkind = 'r' and lower(relnamespace::regnamespace::text) not in 
> ('pg_catalog','partman','information_schema')  and
> lower(relnamespace::regnamespace::text) in ('XYZ')
> order by  relnamespace::regnamespace::text, relname ;

-- 
Adrian Klaver
adrian.klaver@aklaver.com




pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Need exact SQL query to find List of Detach Partitioned Tables (Yet to be Dropped)
Next
From: Achilleas Mantzios
Date:
Subject: Re: Getting error 42P02, despite query parameter being sent