Skip site navigation (1) Skip section navigation (2)

top-level DML under CTEs

From: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: top-level DML under CTEs
Date: 2010-09-13 13:15:24
Message-ID: AANLkTik=9_qeoXSvqX0STaUaR4bZexuykBPTO8OpyyoZ@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-rrreviewers
The patch attached is based on the one rejected at the last CF for 9.0
last year.

http://archives.postgresql.org/message-id/16303.1266023203@sss.pgh.pa.us

This patch implements the feature that allows top-level DMLs under CTE
WITH clause. For example:

WITH t AS (SELECT * FROM x)
UPDATE y SET val = t.val FROM t
WHERE y.key = t.key;

This feature is part of writeable CTEs proposed by David Fetter originally.

There were two issues at the CF.

1. WITH clause atop INSERT
Although the previous discussion got the consensus that we forbid WITH
atop INSERT, it seems to me that it can be allowed. I managed to do it
by treating the top WITH clause (of INSERT) as if the one of SELECT
(or VALUES). It is possible to disallow the CTE over INSERT statement,
but the lack for INSERT, though there are for UPDATE and DELETE,
sounds inconsistent enough.

2. OLD/NEW in rules
Following the subsequent discussion after the post linked above, I add
code to throw an appropriate error when OLD/NEW is used in WITH
clauses. It is true that OLD/NEW references look sane to general
users, but actually (at least in our implementation) they are located
in the top-level query's Range Table List. Consequently, they are
invisible inside the WITH clause. To allow them, we should rewrite the
rule systems overall. Thus, we forbid them in WITH though we should
throw an error indicating appropriate message.

I'll add the entry to CF app later. Any feedback is welcome.

Regards,


-- 
Hitoshi Harada

Attachment: toplevel-dml-cte.20100913.patch
Description: application/octet-stream (18.6 KB)

Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2010-09-13 13:20:19
Subject: Re: top-level DML under CTEs
Previous:From: Heikki LinnakangasDate: 2010-09-13 13:01:16
Subject: Re: pg_ctl emits strange warning message

pgsql-rrreviewers by date

Next:From: Robert HaasDate: 2010-09-13 13:20:19
Subject: Re: top-level DML under CTEs
Previous:From: Robert HaasDate: 2010-09-13 12:00:16
Subject: Re: [RRR] CommitFest 2010-07 final report

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group