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