apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.92k stars 1.12k forks source link

Support prepared statement arguments in the LIMIT clause #12294

Open WeCodingNow opened 2 weeks ago

WeCodingNow commented 2 weeks ago

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 https://github.com/apache/datafusion/blob/ac74cd3163e43563807a8c6e8e72bb058cb6f459/datafusion/sql/src/query.rs#L101-L114

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

![image](https://github.com/user-attachments/assets/b937e41d-f352-45f9-85c9-a6799ee46754)

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

jonahgao commented 2 weeks ago

I think it can be easily supported after #9821

WeCodingNow commented 2 weeks ago

I think it can be easily supported after #9821

This issue refers to the PR https://github.com/apache/datafusion/pull/9815 that was closed due to inactivity; is there any way to make a similar PR?

jonahgao commented 2 weeks ago

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.