2023年5月4日(木) 12:51 Tom Lane <tgl@sss.pgh.pa.us>:
>
> 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.
Ah, "OR REPLACE". Knew I was missing something.
> 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.
'k, I will work on a doc patch.
Thanks
Ian Barwick