Cannot convert partitioned table to a view

From: Kouber Saparev <kouber(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Cannot convert partitioned table to a view
Date: 2022-10-06 12:26:33
Message-ID: CAN4RuQt7Yp3CX583y8KR9SbqdxaNo6BmR=RwKD1o=UypgE2bng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there a special reason why masking views behind table partitions is not
allowed?

Trying to do so raises an error:

CREATE RULE "_RETURN" AS ON SELECT TO xxx_20220715 DO INSTEAD SELECT * FROM
yyy WHERE ...;

ERROR: cannot convert partitioned table "xxx_20220715" to a view

https://github.com/postgres/postgres/blob/master/src/backend/rewrite/rewriteDefine.c#L434

That said, I can trick it if I have a view on a remote server and then
attach it as a remote partition through the foreign data wrapper.

Are there any dangers that should be considered with such an approach?

I noticed that attaching the "_RETURN" rule to a table converts it to a
view, and the operation is irreversible, i.e. once attached, I cannot drop
the rule and put the relation back to a table one.

Cordially,
--
Kouber Saparev

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-10-06 14:02:10 Re: Cannot convert partitioned table to a view
Previous Message Wen Yi 2022-10-06 12:16:52 [Beginner Question]How to generate a call-graph for project?