Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support prepared statement arguments in the LIMIT clause #12294

Closed
WeCodingNow opened this issue Sep 2, 2024 · 3 comments · Fixed by #13088
Closed

Support prepared statement arguments in the LIMIT clause #12294

WeCodingNow opened this issue Sep 2, 2024 · 3 comments · Fixed by #13088
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@WeCodingNow
Copy link

WeCodingNow commented Sep 2, 2024

Is your feature request related to a problem or challenge?

DataFusion: v41.0.0

I want to be able to write the following query as a prepared statement:

PREPARE get_N_rand_ints_from_last_run(INT) AS
SELECT id
FROM
    "test"
WHERE run_id = 'foo'
ORDER BY random()
LIMIT $1

I get the following error message:

Error during planning: Unexpected expression in LIMIT clause

It is impossible, as as it seems that the LIMIT clause supports only constants in it

let fetch = match fetch {
Some(limit_expr)
if limit_expr != sqlparser::ast::Expr::Value(Value::Null) =>
{
let expr = self.sql_to_expr(
limit_expr,
input.schema(),
&mut PlannerContext::new(),
)?;
let n = get_constant_result(&expr, "LIMIT")?;
Some(convert_usize_with_check(n, "LIMIT")?)
}
_ => None,
};

Postgres does support using prepared statement's arguments in the LIMIT clause:

image

Describe the solution you'd like

Support using prepared statement arguments in the LIMIT clause

Describe alternatives you've considered

inapplicable

Additional context

No response

@WeCodingNow WeCodingNow added the enhancement New feature or request label Sep 2, 2024
@jonahgao
Copy link
Member

jonahgao commented Sep 3, 2024

I think it can be easily supported after #9821

@jonahgao jonahgao self-assigned this Sep 3, 2024
@WeCodingNow
Copy link
Author

I think it can be easily supported after #9821

This issue refers to the PR #9815 that was closed due to inactivity; is there any way to make a similar PR?

@jonahgao
Copy link
Member

jonahgao commented Sep 3, 2024

I think it can be easily supported after #9821

This issue refers to the PR #9815 that was closed due to inactivity; is there any way to make a similar PR?

I plan to work on it in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants