diff --git a/src/frontend/planner_test/tests/testdata/input/subquery.yaml b/src/frontend/planner_test/tests/testdata/input/subquery.yaml index aa88505aa6741..dbff030d081e8 100644 --- a/src/frontend/planner_test/tests/testdata/input/subquery.yaml +++ b/src/frontend/planner_test/tests/testdata/input/subquery.yaml @@ -307,3 +307,8 @@ select Array(select 1 union select 2); expected_outputs: - batch_plan +- name: Only table-in-out functions can have subquery parameters. issue 14734 + sql: | + SELECT anon_1.f1 AS "IntegerRange(0, -2, 1)" FROM unnest(CASE WHEN (nullif(1, 0) IS NOT NULL AND sign(1) = sign( -2 - 0)) THEN array_remove(array((SELECT generate_series(0, -2, 1) AS generate_series_1)), -2) ELSE CAST(ARRAY[] AS SMALLINT[]) END) AS anon_1(f1); + expected_outputs: + - binder_error diff --git a/src/frontend/planner_test/tests/testdata/output/subquery.yaml b/src/frontend/planner_test/tests/testdata/output/subquery.yaml index 554525b391efd..9b5ced9a051ce 100644 --- a/src/frontend/planner_test/tests/testdata/output/subquery.yaml +++ b/src/frontend/planner_test/tests/testdata/output/subquery.yaml @@ -873,7 +873,7 @@ - name: Only table-in-out functions can have subquery parameters. sql: | SELECT * FROM generate_series(1, (select 1)); - binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters, generate_series only accepts constant parameters' + binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters. The table function has subquery parameters is generate_series' - name: While this one is allowed. sql: | SELECT generate_series(1, (select 1)); @@ -894,3 +894,7 @@ └─BatchHashAgg { group_key: [1:Int32], aggs: [] } └─BatchExchange { order: [], dist: HashShard(1:Int32) } └─BatchValues { rows: [[1:Int32], [2:Int32]] } +- name: Only table-in-out functions can have subquery parameters. issue 14734 + sql: | + SELECT anon_1.f1 AS "IntegerRange(0, -2, 1)" FROM unnest(CASE WHEN (nullif(1, 0) IS NOT NULL AND sign(1) = sign( -2 - 0)) THEN array_remove(array((SELECT generate_series(0, -2, 1) AS generate_series_1)), -2) ELSE CAST(ARRAY[] AS SMALLINT[]) END) AS anon_1(f1); + binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters. The table function has subquery parameters is unnest' diff --git a/src/frontend/src/binder/relation/table_function.rs b/src/frontend/src/binder/relation/table_function.rs index dbd015351bb5b..d4c0df1f82e60 100644 --- a/src/frontend/src/binder/relation/table_function.rs +++ b/src/frontend/src/binder/relation/table_function.rs @@ -119,14 +119,10 @@ impl Binder { let func = func?; if let ExprImpl::TableFunction(func) = &func { - if func - .args - .iter() - .any(|arg| matches!(arg, ExprImpl::Subquery(_))) - { + if func.args.iter().any(|arg| arg.has_subquery()) { // Same error reports as DuckDB. return Err(ErrorCode::InvalidInputSyntax( - format!("Only table-in-out functions can have subquery parameters, {} only accepts constant parameters", func.name()), + format!("Only table-in-out functions can have subquery parameters. The table function has subquery parameters is {}", func.name()), ) .into()); }