On Fri, Feb 24, 2017 at 9:35 AM, David Fetter <david@fetter.org> wrote:
> => SELECT "?column"? FROM (select 1+1 as "?column?", 1+1) AS x; > ERROR: 42703: column "?column" does not exist > LINE 2: SELECT "?column"? FROM (select 1+1 as "?column?", 1+1) AS x; > ^ > HINT: Perhaps you meant to reference the column "x.?column?" or the > column "x.?column?".
This is indirectly pointing out the duplication since the hint is specifying the exact same name twice...
I don't know how far comparing apples and oranges gets us here...and the assignment of names to expression columns lacking aliases is a bit smarter than given credit for here - e.g., it uses the name of the function in a simple function call expression.
There is no risk of naming conflicts in pre-existing queries. I say we do something like: pg_subquery_n and make it known that the value for "n" will be chosen independent of names already present in the query. We've recently reserved the pg_ prefix for roles we might as well leverage that. These names need only be available for internal needs; as a user I'd expect it is be noted as an implementation detail that should not be relied upon. Whether it needs to get exposed for technical reasons (e.g., dump/restore and explain) I do not know.