4 ms·
It actually appears to go the other way. Explicitly referencing an ambiguous column causes the error while using select * avoids it, at least with duckdb (which
by ted_dunning 5y ago
It actually appears to go the other way. Explicitly referencing an ambiguous column causes the error while using select * avoids it, at least with duckdb (which is a very standard sort of SQL). This suggests to me that using select * in views is a very good practice.
D create table a (amb integer, a1 integer, a2 integer);
D create table b (amb varchar, b1 integer, b2 integer);
D insert into a values (1,1,1);
D insert into b values ('b',2,2);
D insert into b values ('b',1,3);
D select * from a, b where a.a1 = b.b1;
┌─────┬────┬────┬─────┬────┬────┐
│ amb │ a1 │ a2 │ amb │ b1 │ b2 │
├─────┼────┼────┼─────┼────┼────┤
│ 1 │ 1 │ 1 │ b │ 1 │ 3 │
└─────┴────┴────┴─────┴────┴────┘
D select amb from a, b where a.a1 = b.b1;
Error: Binder Error: Ambiguous reference to column name "amb" (use: "b.amb" or "a.amb")
- listenallyall 5y agoThe database query analyzer is doing you a favor by telling you there's an ambiguous column name and refusing to run, for the same reason a compiler won't allow you to define the same variable name twice.