cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.04k stars 3.8k forks source link

Relation appears as a `record` field within itself #120625

Open philip-stoev opened 7 months ago

philip-stoev commented 7 months ago

Describe the problem

In CRDB, apparently a relation appears as a record field within the relation itself. This can result in unexpected results on typos.

To Reproduce

create table t1(f1 integer);
insert into t1 values (1);
select t1.t1 from t1;
f1
-------
 (1)

Expected behavior

In Postgres, this justifiably errors out with a helpful hint, which I think is the safer behavior:

ERROR:  column t1.t1 does not exist
LINE 1: select t1.t1 from t1;
               ^
HINT:  Perhaps you meant to reference the column "t1.f1".

Environment:

Additional context Impact:

Consider the case where a typo was made in the WHERE clause, e.g. WHERE t1.t1 IS NULL. That condition will evaluate whether the entire record is NULL (usually FALSE, unless the record is all-NULLs), rather than a specific column, resulting in an subtle wrong result being returned from the query.

Jira issue: CRDB-36787

blathers-crl[bot] commented 7 months ago

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.