Re: resolving SQL ambiguity (was Re: WIP: Allow SQL-lang funcs to ref params by param name)

From: Darren Duncan <darren(at)darrenduncan(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: resolving SQL ambiguity (was Re: WIP: Allow SQL-lang funcs to ref params by param name)
Date: 2011-03-26 20:38:37
Message-ID: 4D8E4ECD.1010700@darrenduncan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule wrote:
> 2011/3/26 Darren Duncan <darren(at)darrenduncan(dot)net>:
>> I mention 2 possible solutions here, both which involve syntax alterations,
>> each between the ---------- lines. I personally like the second/lower
>> option more.
>
> -1
>
> this is not based on any pattern on SQL. It's not simple, and it
> introduce a reserved keywords

Okay, here's a much simpler proposal with the most important bit of the old one.

1. In all situations where there is ambiguity such that an identifier reference
(not declaration) may be referring to either a lexical variable/parameter of the
current routine, or to the name of the table column of the contextually current
table of the current SQL statement, the ambiguity is always resolved in favor of
the lexical var/param. If I am not mistaken, that is what PL/PgSQL already does
since 9.0.

2. If an identifier reference has a leading "." then that will force it to be
interpreted as a column instead (and the code will fail if there is no such
column), and so ".colname" is a shorthand for "tablename.colname"; but like with
the old "colname" it only works when just 1 of the source tables has "colname"
else it is still ambiguous like before.

Example:

select (.mycol + myvar * myparam) as mynewcol from mytbl;

This solution is a very terse and understandable change.

There are no reserved keywords. Legacy user code has no change where there were
no conflicts before. Legacy user code has no change in the case of conflict if
it was previously resolved to favor the lexical var/param.

Legacy user code only gains a leading "." in the few places where conflict was
resolved in favor of a column name before where a same-named lexical/param existed.

So what's not to like about this?

-- Darren Duncan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-03-26 20:53:11 Re: resolving SQL ambiguity (was Re: WIP: Allow SQL-lang funcs to ref params by param name)
Previous Message Jan Wieck 2011-03-26 20:16:49 Re: Lock problem with autovacuum truncating heap