Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions prqlc/prqlc/src/semantic/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,17 @@ impl Lowerer {
.try_collect()?,
),
pl::ExprKind::RqOperator { name, args } => {
// Check for relation types used as operator arguments
for arg in &args {
if arg.ty.as_ref().is_some_and(|x| x.is_relation()) {
return Err(Error::new_simple(
"table variable cannot be used as a scalar value",
)
.push_hint("use a join instead, or inline the subquery")
.with_span(arg.span));
}
}

let args = args.into_iter().map(|x| self.lower_expr(x)).try_collect()?;

rq::ExprKind::Operator { name, args }
Expand Down
24 changes: 24 additions & 0 deletions prqlc/prqlc/tests/integration/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4053,6 +4053,30 @@ fn test_direct_table_references() {
");
}

#[test]
fn test_table_variable_in_scalar_context() {
// https://github.com/PRQL/prql/issues/5158
assert_snapshot!(compile(
r#"
let mod_id = (from users | filter login == "nightpool" | select id | take 1)

from modlog
filter actor_id == mod_id
"#,
)
.unwrap_err(), @r#"
Error:
╭─[ :5:24 ]
5 │ filter actor_id == mod_id
│ ───┬──
│ ╰──── table variable cannot be used as a scalar value
│ Help: use a join instead, or inline the subquery
───╯
"#);
}

#[test]
fn test_name_shadowing() {
assert_snapshot!(compile(
Expand Down