From needthistool@gmail.com Fri Nov 13 23:06:27 2015 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZxNQJ-0007zb-Ng for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Nov 2015 23:06:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZxNQJ-0007Ai-4v for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Nov 2015 23:06:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZxLZp-0003Xr-Ls for pgsql-bugs@postgresql.org; Fri, 13 Nov 2015 21:08:09 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZxLZi-0007bm-VD for pgsql-bugs@postgresql.org; Fri, 13 Nov 2015 21:08:08 +0000 MIME-Version: 1.0 Subject: BUG #13775: CREATE RULE documentation seems to be wrong under ON SELECT TO DO INSTEAD SELECT To: pgsql-bugs@postgresql.org From: needthistool@gmail.com Date: Fri, 13 Nov 2015 21:08:00 +0000 Message-ID: <20151113210800.615.72954@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13775 Logged by: Seldom Email address: needthistool@gmail.com PostgreSQL version: 9.2.14 Operating system: Linux 4.1.10-17.31.amzn1.x86_64 #1 (~RHEL 4.8.3-9) Description: >From the docs: "Thus, an ON SELECT rule **effectively** turns the table into a view, whose visible contents are the rows returned by the rule's SELECT command **rather than whatever had been stored in the table** (if anything). It is **considered better style** to write a CREATE VIEW command than to create a real table and define an ON SELECT rule for it." {'**' emphases added} As far as I can tell, the above is no longer correct whatsoever; at least on my own server, the CREATE RULE "_RETURN" syntax **actually** turns the table into a view, dropping the table in question and creating a new view which has the same name and columns as the table (undocumented-ly possible only if there are no indexes, triggers, or foreign-key constraints on the current table, in addition to no rows, which makes the "if anything" remark pretty misleading). The documentation /suggests/ that CREATE VIEW ... be used in place of ON SELECT TO
DO INSTEAD SELECT ... however unless I'm mistaken, this is actually not a **choice**, merely obfuscated sugar for CREATE VIEW. It does not appear possible to shadow a table with an alternate selection-clause which makes the real contents of the table appear different in some way (for instance, adding a default sorting or if one wasn't specified or such). I don't know what the consensus is with regard to what this syntax may do in future, but right now, it appears the docs simply do not relate to the actual behavior of the codebase. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs From tgl@sss.pgh.pa.us Fri Nov 13 23:23:15 2015 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZxNgY-0000I1-Vz for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Nov 2015 23:23:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZxNgY-0002BJ-DK for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Nov 2015 23:23:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZxNgX-0002B9-Tr for pgsql-bugs@postgresql.org; Fri, 13 Nov 2015 23:23:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZxNgV-0001Tw-Lm for pgsql-bugs@postgresql.org; Fri, 13 Nov 2015 23:23:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id tADNN9SM009033; Fri, 13 Nov 2015 18:23:09 -0500 From: Tom Lane To: needthistool@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13775: CREATE RULE documentation seems to be wrong under ON SELECT TO
DO INSTEAD SELECT In-reply-to: <20151113210800.615.72954@wrigleys.postgresql.org> References: <20151113210800.615.72954@wrigleys.postgresql.org> Comments: In-reply-to needthistool@gmail.com message dated "Fri, 13 Nov 2015 21:08:00 +0000" Date: Fri, 13 Nov 2015 18:23:09 -0500 Message-ID: <9032.1447456989@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org needthistool@gmail.com writes: >> From the docs: > "Thus, an ON SELECT rule **effectively** turns the table into a view, whose > visible contents are the rows returned by the rule's SELECT command **rather > than whatever had been stored in the table** (if anything). It is > **considered better style** to write a CREATE VIEW command than to create a > real table and define an ON SELECT rule for it." {'**' emphases added} I don't see anything particularly wrong with those statements... > It does > not appear possible to shadow a table with an alternate selection-clause > which makes the real contents of the table appear different in some way (for > instance, adding a default sorting or if one wasn't specified or such). I don't see anything in the docs that suggests that that's supported, either. The only reason creating an ON SELECT rule is still supported at all is that (1) that used to be how pg_dump dumped views, and (2) that's still how pg_dump dumps views in some corner cases involving circular dependencies. We could get rid of (2); but in view of the need for backwards compatibility with old dump files, it's hard to see when we could drop the syntax entirely, so nobody's bothered. In the meantime, though, there is no expectation that we'd ever support ON SELECT rules that weren't a weird spelling of CREATE VIEW, and I don't see anything in the documentation that suggests differently. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs From needthistool@gmail.com Sat Nov 14 19:10:56 2015 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZxgDw-0000xS-2z for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Nov 2015 19:10:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZxgDv-00086d-GP for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Nov 2015 19:10:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZxfvJ-0004Q2-Fi for pgsql-bugs@postgresql.org; Sat, 14 Nov 2015 18:51:41 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZxfvC-0000Ua-Dx for pgsql-bugs@postgresql.org; Sat, 14 Nov 2015 18:51:41 +0000 Received: by wmww144 with SMTP id w144so65499561wmw.1 for ; Sat, 14 Nov 2015 10:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=wmv5dc23sxr5kC4Km/KWH3Q19rn7rZZ8qOgartooIcQ=; b=1CtIycFCiC4xEOXlEAOT0PTZjHQ+jFrtJDfCxBHf5cORb26lbtxwMOyT96J6Y8q/2C xX7/3hqkjNGlUG9D0GgcTe9BwY4/4l7V6015+qqhTibR4iEv4cI3asTfutkJWhc4Zqk+ cLiiZf9j3EgsGHre+nXPYW9AsXRXzu15oDReSNXfZASqPCsQQblcBNygevGXYa7nvDN8 ipO2EQysuZprrZeicJLOzI8kxnvOafTrBHxCkBoablkXhLsdcFcsV7SmkMYj3V6yAWhA CdAIdyKdF3NMe/BzUDNtovRcHYI3DMk8HfkKPHMBIC8P7/F1LR68lWMOpwnOGC5TC01J 1OKQ== MIME-Version: 1.0 X-Received: by 10.194.79.227 with SMTP id m3mr2691902wjx.123.1447527091409; Sat, 14 Nov 2015 10:51:31 -0800 (PST) Received: by 10.28.215.138 with HTTP; Sat, 14 Nov 2015 10:51:31 -0800 (PST) Date: Sat, 14 Nov 2015 11:51:31 -0700 Message-ID: Subject: Re: BUG #13775: CREATE RULE documentation seems to be wrong under ON SELECT TO
DO INSTEAD SELECT From: Seldom Needy To: Tom Lane Cc: pgsql-bugs@postgresql.org Content-Type: multipart/alternative; boundary=047d7bf0c6b6161ccf052484aaf0 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --047d7bf0c6b6161ccf052484aaf0 Content-Type: text/plain; charset=UTF-8 On Fri, Nov 13, 2015 at 4:23 PM, Tom Lane wrote: > needthistool@gmail.com writes: > >> From the docs: > > > "Thus, an ON SELECT rule **effectively** turns the table into a view, > whose > > visible contents are the rows returned by the rule's SELECT command > **rather > > than whatever had been stored in the table** (if anything). It is > > **considered better style** to write a CREATE VIEW command than to > create a > > real table and define an ON SELECT rule for it." {'**' emphases added} > > I don't see anything particularly wrong with those statements... > > > It does > > not appear possible to shadow a table with an alternate selection-clause > > which makes the real contents of the table appear different in some way > (for > > instance, adding a default sorting or if one wasn't specified or such). > > I don't see anything in the docs that suggests that that's supported, > either. > > The only reason creating an ON SELECT rule is still supported at all is > that (1) that used to be how pg_dump dumped views, and (2) that's still > how pg_dump dumps views in some corner cases involving circular > dependencies. We could get rid of (2); but in view of the need for > backwards compatibility with old dump files, it's hard to see when we > could drop the syntax entirely, so nobody's bothered. In the meantime, > though, there is no expectation that we'd ever support ON SELECT rules > that weren't a weird spelling of CREATE VIEW, and I don't see anything > in the documentation that suggests differently. > > regards, tom lane > "[T]here is no expectation that we'd ever support ON SELECT rules that weren't a weird spelling of CREATE VIEW and I don't see anything in the documentation that suggests differently." I disagree; such an expectation could easily be taken as an inference by some readers of the relevant pages; throughout the rest of the documentation, (for example with CREATE USER versus CREATE ROLE,) it's stated explicitly when one syntax is a functionally-identical sister-syntax to another, (kept around for legacy reasons and/or to allow conformance to SQL-specifications). To state "that particular interpretation of what's written is not the correct one" indicates that the docs are ambiguous in this instance and should be made more clear and moreover more consistent with the conventions of the rest of the documentation, namely in plainly stating why the syntax (still) exists and what it currently does. Further, it's misleading that the documentation suggests that it is merely a frowned-upon choice to use CREATE RULE ... ON SELECT ... DO INSTEAD SELECT when in fact it is not a choice whatsoever. A justifiable takeaway from the current phrasing is that VIEWs are semantically easier to understand and therefore preferred, but somehow different from a DO INSTEAD SELECT. The actual reality is that there is no such thing as a DO INSTEAD SELECT rule. I don't see an argument for leaving that as an ambiguity in the docs, when it is obvious after some experimentation with a server what's actually happening. Why not save folks the time and state this explicitly? Again, it would be helpful for (new) users to be made aware that the CREATE RULE ... ON SELECT syntax exists primarily for sake of compatibility with pg-dump and is in essence another way to invoke CREATE VIEW. Although none of this is currently made explicit, I don't see why it should be left unstated in official documentation, nevermind that it's been made fairly clear here. Respectfully, - Seldom --047d7bf0c6b6161ccf052484aaf0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On F= ri, Nov 13, 2015 at 4:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wr= ote:
needthistool@gmail.com writes:
>> From the docs:

> "Thus, an ON SELECT rule **effectively** turns the table into a v= iew, whose
> visible contents are the rows returned by the rule's SELECT comman= d **rather
> than whatever had been stored in the table** (if anything). It is
> **considered better style** to write a CREATE VIEW command than to cre= ate a
> real table and define an ON SELECT rule for it." {'**' em= phases added}

I don't see anything particularly wrong with those statements...

> It does
> not appear possible to shadow a table with an alternate selection-clau= se
> which makes the real contents of the table appear different in some wa= y (for
> instance, adding a default sorting or if one wasn't specified or s= uch).

I don't see anything in the docs that suggests that that's supporte= d,
either.

The only reason creating an ON SELECT rule is still supported at all is
that (1) that used to be how pg_dump dumped views, and (2) that's still=
how pg_dump dumps views in some corner cases involving circular
dependencies.=C2=A0 We could get rid of (2); but in view of the need for backwards compatibility with old dump files, it's hard to see when we could drop the syntax entirely, so nobody's bothered.=C2=A0 In the mean= time,
though, there is no expectation that we'd ever support ON SELECT rules<= br> that weren't a weird spelling of CREATE VIEW, and I don't see anyth= ing
in the documentation that suggests differently.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane

"[T]here is no expectation that we'd ever s= upport ON SELECT rules that weren't a weird spelling of CREATE VIEW and= I don't see anything in the documentation that suggests differently.&q= uot; I disagree; such an expectation could easily be taken as an inference = by some readers of the relevant pages; throughout the rest of the documenta= tion, (for example with CREATE USER versus CREATE ROLE,) it's stated ex= plicitly when one syntax is a functionally-identical sister-syntax to anoth= er, (kept around for legacy reasons and/or to allow conformance to SQL-spec= ifications). To state "that particular interpretation of what's wr= itten is not the correct one" indicates that the docs are ambiguous in= this instance and should be made more clear and moreover more consistent w= ith the conventions of the rest of the documentation, namely in plainly sta= ting why the syntax (still) exists and what it currently does.

Further, it's misleading that the documenta= tion suggests that it is merely a frowned-upon choice to use CREATE RULE ..= . ON SELECT ... DO INSTEAD SELECT when in fact it is not a choice whatsoeve= r. A justifiable takeaway from the current phrasing is that VIEWs are seman= tically easier to understand and therefore preferred, but somehow different= from a DO INSTEAD SELECT. The actual reality is that there is no such thin= g as a DO INSTEAD SELECT rule. I don't see an argument for leaving that= as an ambiguity in the docs, when it is obvious after some experimentation= with a server what's actually happening. Why not save folks the time a= nd state this explicitly?

Again, it would be helpful for (new) users to be ma= de aware that the CREATE RULE ... ON SELECT syntax exists primarily for sak= e of compatibility with=C2=A0 pg-dump and is in essence another way to invo= ke CREATE VIEW. Although none of this is currently made explicit, I don'= ;t see why it should be left unstated in official documentation, nevermind = that it's been made fairly clear here.

Respectfully,
- Seldom
--047d7bf0c6b6161ccf052484aaf0--