How to retrieve the partition info for each partition table?

Started by Yuxia Qiuover 7 years ago4 messagesgeneral
Jump to latest
#1Yuxia Qiu
yuxiaqiu1@gmail.com

HI,

I have created some partition table, as example bellow:
CREATE TABLE public.measurement
(
city_id integer NOT NULL,
logdate date NOT NULL,
peaktemp integer,
unitsales integer
) PARTITION BY RANGE (logdate) ;

CREATE TABLE public.measurement_y2006m02 PARTITION OF public.measurement
FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');

CREATE TABLE public.measurement_y2006m03 PARTITION OF public.measurement
FOR VALUES FROM ('2006-03-01') TO ('2006-04-01');

I know how to get a list partition tables for above example by calling :

SELECT i.inhrelid::regclass AS child

FROM pg_inherits i

WHERE i.inhparent = 'public.measurement'::regclass;

My question is: how to get the value boundary for each partition table like
bellow?

measurement_y2006m02 FROM ('2006-02-01') TO ('2006-03-01')

measurement_y2006m03 FROM ('2006-03-01') TO ('2006-04-01')

Thanks,

Yuxia

#2Igor Neyman
ineyman@perceptron.com
In reply to: Yuxia Qiu (#1)
RE: How to retrieve the partition info for each partition table?

From: Yuxia Qiu [mailto:yuxiaqiu1@gmail.com]
Sent: Wednesday, October 24, 2018 1:29 PM
To: pgsql-general@lists.postgresql.org
Subject: How to retrieve the partition info for each partition table?

HI,

I have created some partition table, as example bellow:
CREATE TABLE public.measurement
(
city_id integer NOT NULL,
logdate date NOT NULL,
peaktemp integer,
unitsales integer
) PARTITION BY RANGE (logdate) ;

CREATE TABLE public.measurement_y2006m02 PARTITION OF public.measurement
FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');

CREATE TABLE public.measurement_y2006m03 PARTITION OF public.measurement
FOR VALUES FROM ('2006-03-01') TO ('2006-04-01');

I know how to get a list partition tables for above example by calling :
SELECT i.inhrelid::regclass AS child
FROM pg_inherits i
WHERE i.inhparent = 'public.measurement'::regclass;

My question is: how to get the value boundary for each partition table like bellow?
measurement_y2006m02 FROM ('2006-02-01') TO ('2006-03-01')

measurement_y2006m03 FROM ('2006-03-01') TO ('2006-04-01')

Thanks,
Yuxia

Take a look at relpartbound in pg_class.

Regards,
Igor Neyman

#3Igor Neyman
ineyman@perceptron.com
In reply to: Igor Neyman (#2)
RE: How to retrieve the partition info for each partition table?

From: Yuxia Qiu [mailto:yuxiaqiu1@gmail.com]
Sent: Wednesday, October 24, 2018 1:29 PM
To: pgsql-general@lists.postgresql.org<mailto:pgsql-general@lists.postgresql.org>
Subject: How to retrieve the partition info for each partition table?

HI,

I have created some partition table, as example bellow:
CREATE TABLE public.measurement
(
city_id integer NOT NULL,
logdate date NOT NULL,
peaktemp integer,
unitsales integer
) PARTITION BY RANGE (logdate) ;

CREATE TABLE public.measurement_y2006m02 PARTITION OF public.measurement
FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');

CREATE TABLE public.measurement_y2006m03 PARTITION OF public.measurement
FOR VALUES FROM ('2006-03-01') TO ('2006-04-01');

I know how to get a list partition tables for above example by calling :
SELECT i.inhrelid::regclass AS child
FROM pg_inherits i
WHERE i.inhparent = 'public.measurement'::regclass;

My question is: how to get the value boundary for each partition table like bellow?
measurement_y2006m02 FROM ('2006-02-01') TO ('2006-03-01')
measurement_y2006m03 FROM ('2006-03-01') TO ('2006-04-01')

Thanks,
Yuxia

Better yet:

SELECT relname, pg_get_expr(relpartbound, oid) FROM pg_class WHERE relpartbound IS NOT NULL;

Regards,
Igor Neyman

#4Data Ace
dataace9@gmail.com
In reply to: Igor Neyman (#3)
Re: How to retrieve the partition info for each partition table?

Hi everyone. Kindly remove me from the email list. Than you.

On Wed, Oct 24, 2018 at 11:58 AM Igor Neyman <ineyman@perceptron.com> wrote:

Show quoted text

*From:* Yuxia Qiu [mailto:yuxiaqiu1@gmail.com <yuxiaqiu1@gmail.com>]
*Sent:* Wednesday, October 24, 2018 1:29 PM
*To:* pgsql-general@lists.postgresql.org
*Subject:* How to retrieve the partition info for each partition table?

HI,

I have created some partition table, as example bellow:

CREATE TABLE public.measurement

(

city_id integer NOT NULL,

logdate date NOT NULL,

peaktemp integer,

unitsales integer

) PARTITION BY RANGE (logdate) ;

CREATE TABLE public.measurement_y2006m02 PARTITION OF public.measurement

FOR VALUES FROM ('2006-02-01') TO ('2006-03-01');

CREATE TABLE public.measurement_y2006m03 PARTITION OF public.measurement

FOR VALUES FROM ('2006-03-01') TO ('2006-04-01');

I know how to get a list partition tables for above example by calling :

SELECT i.inhrelid::regclass AS child

FROM pg_inherits i

WHERE i.inhparent = 'public.measurement'::regclass;

My question is: how to get the value boundary for each partition table
like bellow?

measurement_y2006m02 FROM ('2006-02-01') TO ('2006-03-01')

measurement_y2006m03 FROM ('2006-03-01') TO ('2006-04-01')

Thanks,

Yuxia

Better yet:

SELECT relname, pg_get_expr(relpartbound, oid) FROM pg_class WHERE
relpartbound IS NOT NULL;

Regards,

Igor Neyman