Re: "CREATE RULE ... ON SELECT": redundant? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: "CREATE RULE ... ON SELECT": redundant?
Date
Msg-id 3063372.1683172290@sss.pgh.pa.us
Whole thread Raw
In response to "CREATE RULE ... ON SELECT": redundant?  (Ian Lawrence Barwick <barwick@gmail.com>)
Responses Re: "CREATE RULE ... ON SELECT": redundant?
Re: "CREATE RULE ... ON SELECT": redundant?
List pgsql-hackers
Ian Lawrence Barwick <barwick@gmail.com> writes:
> While poking around at an update for that, unless I'm missing something it is
> now not possible to use "CREATE RULE ... ON SELECT" for any kind of relation,
> given that it's disallowed on views / material views already.

What makes you think it's disallowed on views?  You do need to use
CREATE OR REPLACE, since the rule will already exist.

regression=# create view v as select * from int8_tbl ;
CREATE VIEW
regression=# create or replace rule "_RETURN" as on select to v do instead select q1, q2+1 as q2 from int8_tbl ;
CREATE RULE
regression=# \d+ v
                             View "public.v"
 Column |  Type  | Collation | Nullable | Default | Storage | Description
--------+--------+-----------+----------+---------+---------+-------------
 q1     | bigint |           |          |         | plain   |
 q2     | bigint |           |          |         | plain   |
View definition:
 SELECT int8_tbl.q1,
    int8_tbl.q2 + 1 AS q2
   FROM int8_tbl;

Now, this is certainly syntax that's deprecated in favor of using
CREATE OR REPLACE VIEW, but I'm very hesitant to remove it.  ISTR
that ancient pg_dump files used it in cases involving circular
dependencies.  If you want to adjust the docs to say that it's
deprecated in favor of CREATE OR REPLACE VIEW, I could get on
board with that.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Ian Lawrence Barwick
Date:
Subject: "CREATE RULE ... ON SELECT": redundant?
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: [PoC] pg_upgrade: allow to upgrade publisher node