Re: A problem with dump/restore of views containing whole row references
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Abbas Butt <abbas.butt@enterprisedb.com>
Cc: Andrew Dunstan <andrew@dunslane.net>, pgsql-hackers@postgresql.org
Date: 2012-04-27T22:41:50Z
Lists: pgsql-hackers
Attachments
- whole-row-var-printing.patch (text/x-patch) patch
Abbas Butt <abbas.butt@enterprisedb.com> writes: > On Fri, Apr 27, 2012 at 11:21 PM, Tom Lane <tgl@sss.pgh.pa.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