偶小梦
发布于

显示时隐藏分区表的子分区表

➢ 问题
分区表太多在 DBvisual 或者 PGAdmin 里面看起来太长,找不到表。希望我们能在这里隐藏分区表。

➢ 解答
可以先创建新的用于存储 parittion table 的 schema,然后在新的 schema 内创建 partition table,最后在默认的 schema 内创建一个同名的 view 指向 partition table。

这样的话只会在存储 parittion table 的 schema 内看见 partition table 的子表,但是在默认的 schema 内只看见与 partition table 同名的 view。该 view 的功能和原有的 partition table 是一致的。

demo=# show search_path ;
search_path

"$user",public
(1 row)

demo=# \d
No relations found.

demo=# create schema sales;
CREATE SCHEMA

demo=# CREATE TABLE sales.sales (id int, date date, amt decimal(10,2)) DISTRIBUTED BY (id) PARTITION BY RANGE (date) ( START (date '2008-01-01') INCLUSIVE END (date '2008-01-10') EXCLUSIVE EVERY (INTERVAL '1 day') );
NOTICE: CREATE TABLE will create partition "sales_1_prt_1" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_2" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_3" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_4" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_5" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_6" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_7" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_8" for table "sales"
NOTICE: CREATE TABLE will create partition "sales_1_prt_9" for table "sales"
CREATE TABLE

demo=# create view sales as select * from sales.sales;
CREATE VIEW

demo=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+-------+------+-------+---------
public | sales | view | admin | none
(1 row)

demo=# \d sales
View "public.sales"
Column | Type | Modifiers
--------+---------------+-----------
id | integer |
date | date |
amt | numeric(10,2) |
View definition:
SELECT sales.id, sales.date, sales.amt
FROM sales.sales;

demo=# set search_path to sales;
SET

demo=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+---------------+-------+-------+-------------
sales | sales | table | admin | append only
sales | sales_1_prt_1 | table | admin | append only
sales | sales_1_prt_2 | table | admin | append only
sales | sales_1_prt_3 | table | admin | append only
sales | sales_1_prt_4 | table | admin | append only
sales | sales_1_prt_5 | table | admin | append only
sales | sales_1_prt_6 | table | admin | append only
sales | sales_1_prt_7 | table | admin | append only
sales | sales_1_prt_8 | table | admin | append only
sales | sales_1_prt_9 | table | admin | append only
(10 rows)

评论
    test