Re: incomplete CTE declaration and "column reference x is ambiguous"

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: incomplete CTE declaration and "column reference x is ambiguous"
Date: 2013-07-01 16:04:38
Message-ID: 1372694678860-5762048.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marc Mamin-2 wrote
> Hello,
>
> I've lost some time to debug a large Query with many CTE.
> I couldn't really believe the error message.
>
> it was correct after all , though surprising.
> a short version to illustrate my error:
>
> WITH t1 (a,b) AS (
> SELECT
> 1 as x,
> 2 as a,
> 3 as b
> )
> select * from t1 WHERE b =0
>
> ERROR: column reference "b" is ambiguous.
>
>
> It would be nice, if extra undeclared columns would not be visible outside
> the CTE.
>
> regards,
>
> Marc Mamin

That ship has already sailed.

At least this way you know you are confused somewhere (or missed changing
something). If you only want two output columns you should modify the query
to explicitly state which two you want.

If anything I'd rather enforce an "all-or-nothing" approach where your query
throws an "Invalid CTE Definition - the number of declared columns does not
match the actual column count" error instead. If I add a column in the
middle of the SELECT list and forget to change the output columns the error
will tell me I forgot something instead of simply re-aliasing all of my
columns and then continuing as if nothing is wrong.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/incomplete-CTE-declaration-and-column-reference-x-is-ambiguous-tp5762037p5762048.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message 高健 2013-07-02 00:42:14 What is the difference between cmin and cmax
Previous Message Michael Orlitzky 2013-07-01 15:05:11 Re: (Default) Group permissions