Subject: Re: Getting specific partition from the partition name

From: Greg Sabino Mullane <[email-masked]>
Date: Thu, 8 Aug 2024 16:45:18 -0400

YYYY_MM_DD is already setup for sorting, so just do:

SELECT table_name FROM information_schema.tables WHERE table_name ~
'table_part_p' ORDER BY 1 DESC;

If you need to grab the numbers:

SELECT substring('table_part_p2022_03_04' from '([\d_]+)$');

Cheers,
Greg

---

From: Ron Johnson <[email-masked]>
Date: Fri, 9 Aug 2024 00:20:04 -0400

> SELECT substring('table_part_p2022_03_04' from '([\d_]+)$');

What if the partitions aren't all rationally named?  There *must* be a pg_*
table out there which contains the partition boundaries...

-- 
Death to America, and butter sauce.
Iraq lobster!

---

From: veem v <[email-masked]>
Date: Fri, 9 Aug 2024 16:53:09 +0530

This helps. Thank you very much.

---

From: GF <[email-masked]>
Date: Fri, 9 Aug 2024 17:34:54 +0200

On Fri, 9 Aug 2024 at 06:20, Ron Johnson <[email-masked]> wrote:

>
> What if the partitions aren't all rationally named?  There *must* be a
> pg_* table out there which contains the partition boundaries...
>
>
The pg_class column relpartbound contains an internal representation of the
partition boundary, when applicable.
You can decompile it into the canonical text format with pg_get_expr( expr
pg_node_tree, relation oid [, pretty boolean ] ) → text.
So:
    create table t(x int primary key) partition by list(x);
    create table u partition of t for values in (0,1);
    create table v partition of t for values in (2,3,4,5,6,7,8,9);
    select oid::regclass,pg_get_expr(relpartbound,oid) from pg_class where
relkind='r' and relispartition;
 oid |              pg_get_expr
-----+----------------------------------------
 u   | FOR VALUES IN (0, 1)
 v   | FOR VALUES IN (2, 3, 4, 5, 6, 7, 8, 9)
(2 rows)

Best,
Giovanni