prql
prql copied to clipboard
Error when column names clash with variable names
What's up?
So this seems to be by design but definitely came off as a bug when I first encountered it.
This does not look like there should be any issue:
prql target:sql.postgres
let name = 'asdf' # Causes error
let foo = (
from sometable
select {
id,
name
}
)
from foo
Error:
╭─[:13:6]
│
13 │ from foo
│ ─┬─
│ ╰─── This table contains unnamed columns that need to be referenced by name
- The error is a bit confusing
- If I add
select {id, name}
to the finalfrom foo
then it selects the variablename
instead of the column. It would be nice if we could disambiguate the situation by specifying{name = foo.name}
or something. - Trying the above results in the following which is even more confusing because without the variable it works:
Error:
╭─[:14:18]
│
14 │ select {id, name=foo.name}
│ ────┬───
│ ╰───── Unknown name `foo.name`
────╯
...which is exactly how I first found this issue when trying to upgrade from 0.8.1. An existing large query was joining tables and somehow one column seemed to go missing half-way through the query xD
Yes, this does seem like a bug. In particular, this works:
let name = 'asdf'
from sometable
select {
id,
name
}
...but when in let foo = ... ... from foo
, then it raises an error...