Re: Values list-of-targetlists patch for comments (was Re: [HACKERS] 8.2 features?)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Christopher Kings-Lynne <chris(dot)kings-lynne(at)calorieking(dot)com>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Bernd Helmle <mailings(at)oopsware(dot)de>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Susanne Ebrecht <susanne(dot)ebrecht(at)credativ(dot)de>
Subject: Re: Values list-of-targetlists patch for comments (was Re: [HACKERS] 8.2 features?)
Date: 2006-07-24 17:09:29
Message-ID: 12029.1153760969@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers pgsql-patches

Joe Conway <mail(at)joeconway(dot)com> writes:
> Good feedback -- thanks! But without the RTE, how would VALUES in the
> FROM clause work?

Is it different from INSERT? I'm just imagining a Values node in
the jointree and nothing in the rangetable.

If I'm reading the spec correctly, VALUES is exactly parallel to SELECT
in the grammar, which means that to use it in FROM you would need
parentheses and an alias:

SELECT ... FROM (SELECT ...) AS foo

SELECT ... FROM (VALUES ...) AS foo

ISTM that this should be represented using an RTE_SUBQUERY node in the
outer query; the alias attaches to that node, not to the VALUES itself.
So I don't think you need that alias field in the jointree entry either.

If we stick with the plan of representing VALUES as if it were SELECT *
FROM (valuesnode), then this approach would make the second query above
have a structure like

Query
.rtable -> RTE_SUBQUERY
.subquery -> Query
.jointree -> Values

(leaving out a ton of detail of course, but those are the key nodes).

To get this to reverse-list in the expected form, we'd need a small
kluge in ruleutils.c that short-circuits the display of "SELECT
... FROM" etc when it sees a Values node at the top of the jointree.
This seems like a fairly small price to pay for keeping Query in
approximately its present form, though.

One thought is that we might allow Query.jointree to point to either
a FromExpr or a Values node, and disallow Values from appearing further
down in the jointree (except perhaps after flattening of subqueries
in the planner). The alternative is that there's a FromExpr atop
the Values node in the jointree even in the simple case; which seems
uglier but it might avoid breaking some code that expects the top level
to always be FromExpr.

regards, tom lane

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Joe Conway 2006-07-24 21:22:29 Re: Values list-of-targetlists patch for comments (was Re:
Previous Message Joe Conway 2006-07-24 16:32:37 Re: Values list-of-targetlists patch for comments (was Re:

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2006-07-24 17:12:33 Re: plPHP and plRuby
Previous Message Peter Eisentraut 2006-07-24 17:09:17 Re: Allow commenting of variables in postgresql.conf to - try 4

Browse pgsql-patches by date

  From Date Subject
Next Message Joachim Wieland 2006-07-24 17:24:12 Re: Allow commenting of variables in postgresql.conf to - try 4
Previous Message Peter Eisentraut 2006-07-24 17:09:17 Re: Allow commenting of variables in postgresql.conf to - try 4