Skip to content

Parameterised Queries: Interactive SQL Query Parameters in SQL Console #2944

Description

@Pinchez25

Chat2DB Edition

Chat2DB Community

User Problem

When running the same SQL query repeatedly with different values in the WHERE clause, I currently have to edit the SQL each time to change the value.

For example, changing:

WHERE id = 42;

to:

WHERE id = 43;

every time I want to query a different record becomes tedious, especially for longer or more complex queries.

Concrete Use Case

It would be useful to define a parameter directly in the SQL:

SELECT
  report_name,
  report_type
FROM fineract_default.stretchy_report
WHERE id = :id;

When the query is executed, Chat2DB could detect :id and prompt the user to provide its value:

id: [ 42 ]

The same query could then be executed again with a different value without modifying the SQL.

This could also support multiple parameters:

SELECT *
FROM some_table
WHERE client_id = :client_id
  AND status = :status;

with Chat2DB prompting for both values when the query is run.

Product Area

SQL editor

Proposed Outcome

Add support for interactive SQL query parameters in the SQL editor.

When a query contains parameters, Chat2DB should:

  1. Detect the parameters in the query.
  2. Prompt the user for their values when the query is executed.
  3. Bind the supplied values to the query.
  4. Execute the query without requiring the SQL itself to be modified.

Named parameters such as :id would be particularly useful, although support for other parameter syntaxes could also be considered depending on the database/driver.

Alternatives Considered

No response

Contribution

I can help test the change

Submission Checklist

  • I searched existing issues and Discussions for duplicates.
  • I selected the affected Chat2DB edition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions