From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Simon Riggs" <simon(at)2ndquadrant(dot)com>, <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [GENERAL] Count(*) throws error |
Date: | 2007-07-12 15:06:32 |
Message-ID: | 873aztmzk7.fsf@oxford.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
>> On Wed, 2007-07-11 at 18:13 -0400, Tom Lane wrote:
>>> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
>>>> Seems like we could be slightly more friendly without too much bother:
>>>> at least only substitute after the VALUES clause in INSERT.
>>>
>>> Surely you jest.
>
>> No. There are a places where parameters clearly aren't allowed, so
>> making the substitutions in those places can easily be prevented. The
>> remainder of the problem is as hard as you think, but getting half way
>> there seems very easy.
>
> It's not nearly as easy as you think. Even for the limited case of
> the column list for an INSERT, consider
>
> DECLARE i int; j int;
> ...
> INSERT INTO mytable (arraycol[i]) VALUES (j);
huh, i hadn't actually seen that before -- it doesn't seem very useful. But
I've certainly seen and used "UPDATE SET arraycol[i] = val".
> Considering that the current plpgsql parser doesn't have any knowledge
> *at all* of the syntactic structure of individual SQL commands, even
> teaching it to recognize an INSERT column list correctly would be a huge
> addition of code.
It does eventually call the SQL parser though doesn't it? I was thinking the
way to do it would be to delay substituting the formal parameters to later,
after the parsing.
So instead of substituting them as the tokens are lexed, instead suck in the
tokens, run the parser -- which we currently do anyways just to check the
syntax -- then walk the tree looking for ColumnRefs where the name matches a
variable name. Then keep around that parse tree instead of just the series of
lex tokens to later call analyze on and execute.
> The other problem with trying to inject a small amount of smarts is that
> it complicates explaining the system.
Well that's quite true, but then that's the basic difficulty with any part of
plpgsql.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Koen Vermeer | 2007-07-12 15:26:06 | libpq: Specify pass phrase for SSL key |
Previous Message | Tom Lane | 2007-07-12 14:54:29 | Re: [GENERAL] Count(*) throws error |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2007-07-12 15:17:25 | Re: 2PC-induced lockup |
Previous Message | Florian G. Pflug | 2007-07-12 15:02:36 | Re: xlog switch & last record before the switch |