-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Labels
Description
What happens?
Generally speaking, one can write a lambda x : ...
and expect x
to be bound inside of the body of the function. However, this does not work when the function is used inside of an ALTER TABLE
statement (e.g., to modify the type of a column), even when the exact same function works elsewhere. Instead it results in the error:
Binder Error:
Table does not contain column x referenced in alter statement!
To Reproduce
Reproducer (save as duckdb_test.sql
):
CREATE TABLE test (asdf VARCHAR[]);
INSERT INTO test VALUES (NULL), ([]), (['asdf']), (['qwer', 'CXZASDF']);
-- The lambda inside list_transform fails to capture its parameter x:
ALTER TABLE test
ALTER COLUMN asdf TYPE STRUCT(title VARCHAR)[]
USING (list_transform(asdf, lambda x : { 'title': x }));
SELECT * from test;
-- For comparison, direct use of list_transform works fine:
SELECT list_transform(['zxcv', 'ghjk'], lambda x : { 'title': x });
Output with DuckDB 1.3.0 stable:
$ duckdb -f duckdb_test.sql
Binder Error:
Table does not contain column x referenced in alter statement!
┌─────────────────┐
│ asdf │
│ varchar[] │
├─────────────────┤
│ NULL │
│ [] │
│ [asdf] │
│ [qwer, CXZASDF] │
└─────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────────┐
│ list_transform(main.list_value('zxcv', 'ghjk'), (lambda x: main.struct_pack(title := x))) │
│ struct(title varchar)[] │
├───────────────────────────────────────────────────────────────────────────────────────────┤
│ [{'title': zxcv}, {'title': ghjk}] │
└───────────────────────────────────────────────────────────────────────────────────────────┘
Output with latest nightly:
$ ./duckdb --version
v1.3.0-dev3597 c43ab41ad4
$ ./duckdb -f duckdb_test.sql
Binder Error:
Table does not contain column x referenced in alter statement!
┌─────────────────┐
│ asdf │
│ varchar[] │
├─────────────────┤
│ NULL │
│ [] │
│ [asdf] │
│ [qwer, CXZASDF] │
└─────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────────┐
│ list_transform(main.list_value('zxcv', 'ghjk'), (lambda x: main.struct_pack(title := x))) │
│ struct(title varchar)[] │
├───────────────────────────────────────────────────────────────────────────────────────────┤
│ [{'title': zxcv}, {'title': ghjk}] │
└───────────────────────────────────────────────────────────────────────────────────────────┘
OS:
macOS x86
DuckDB Version:
1.3.0
DuckDB Client:
CLI
Hardware:
No response
Full Name:
Elliott Slaughter
Affiliation:
SLAC
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a nightly build
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?
- Yes, I have