Skip to content

Commit e8278e1

Browse files
committed
Pin that a widening cast of a key does not carry its dependencies
1 parent 9d9f9f3 commit e8278e1

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎datafusion/sqllogictest/test_files/functional_dependencies.slt‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,20 @@ SELECT CAST(x AS INT) k, y FROM t_cast GROUP BY CAST(x AS INT), y ORDER BY k, y;
401401
query error DataFusion error: Error during planning: Column in SELECT must be in GROUP BY or an aggregate function
402402
SELECT y, count(*) FROM t_cast GROUP BY CAST(x AS INT);
403403

404+
statement ok
405+
drop table t_cast;
406+
404407
# 6.5 Only the key column itself carries the dependency, even when the cast
405-
# keeps distinct values distinct. PostgreSQL and DuckDB reject this too.
408+
# keeps distinct values distinct, like INT to BIGINT. PostgreSQL and DuckDB
409+
# reject this too.
410+
statement ok
411+
CREATE TABLE t_wide (x INT, y VARCHAR, PRIMARY KEY (x)) AS VALUES (1, 'b'), (2, 'a');
412+
406413
query error DataFusion error: Error during planning: Column in SELECT must be in GROUP BY or an aggregate function
407-
SELECT y, count(*) FROM t_cast GROUP BY CAST(x AS VARCHAR);
414+
SELECT y, count(*) FROM t_wide GROUP BY CAST(x AS BIGINT);
408415

409416
statement ok
410-
drop table t_cast;
417+
drop table t_wide;
411418

412419
# 6.6 The same with `TRY_CAST` over a `UNIQUE NOT NULL` key: 'bad-a' and
413420
# 'bad-b' both cast to NULL.

‎docs/source/library-user-guide/upgrading/56.0.0.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ expression over the key is now rejected, as in PostgreSQL and DuckDB. Group by
887887
the key column itself instead:
888888

889889
```sql
890-
-- `id` is the PRIMARY KEY of `t`
890+
-- `id` is the INT PRIMARY KEY of `t`
891891
SELECT name FROM t GROUP BY CAST(id AS BIGINT); -- now an error
892892
SELECT name FROM t GROUP BY id; -- ok
893893
```

0 commit comments

Comments
 (0)