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: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-rrreviewers
The patch attached is based on the one rejected at the last CF for 9.0
last year.

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

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.


Hitoshi Harada

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


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-2018 The PostgreSQL Global Development Group