From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Abbas Butt <abbas(dot)butt(at)enterprisedb(dot)com> |
Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: A problem with dump/restore of views containing whole row references |
Date: | 2012-04-27 22:41:50 |
Message-ID: | 4244.1335566510@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Abbas Butt <abbas(dot)butt(at)enterprisedb(dot)com> writes:
> On Fri, Apr 27, 2012 at 11:21 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> More generally, it seems rather inelegant to be forcibly adding a cast
>> when in most cases the existing notation is not wrong. AFAICS the
>> plain "relname" notation is only ambiguous if there is a column of the
>> same name as the relation. I wonder whether we should instead address
>> this by not letting the parser strip the "no op" cast in the first
>> place.
> You mean that the parser should not strip the "no op" cast in all cases or
> in the case only when the parser somehow detects a column of the same name
> as the relation?
On reflection that's the wrong thing anyway. While (AFAICS) one could
only initially create this type of situation by using an explicit cast
as in your example, the ambiguity could be introduced after the fact by
a rename or ALTER TABLE ADD COLUMN, which wouldn't even have to affect
the troublesome table itself --- a column matching the table's name
anywhere in the FROM clause would create the same ambiguity. So there's
no guarantee that there ever was a cast there.
So I think that your patch is the right approach, if wrong in detail.
What we have to do is stop using the ambiguous table-name-only syntax,
and instead always print tabname.*, and then add a cast to prevent
expansion of the "*" if we are at top level of a SELECT targetlist.
Attached is a patch that I think does this correctly. I renamed the
flag parameter (and flipped its sense) since it is no longer controlling
whether or not a "*" gets printed. One thing I like about this is that
whole-row Vars are no longer ever special in terms of naming; looking
at the code with a fresh eye, I wonder whether we didn't have other bugs
here in cases such as where a schema qualification is needed. Omitting
the star is just asking for trouble ...
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
whole-row-var-printing.patch | text/x-patch | 5.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2012-04-27 22:48:49 | Re: xReader, double-effort |
Previous Message | Andres Freund | 2012-04-27 22:32:43 | Re: Re: xReader, double-effort (was: Temporary tables under hot standby) |