Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
sahubibhuti45
Helper I
Helper I

Dynamic Parameter input in python query

Hi Team,

I am taking data from a simple query like "Select * from table limit 10 in my python script;

I want to make the limit 10 number to be dynamic so that whenever user enters a number in front it should show the number of rows.

 

I have created a parameter and then I have created a table with a list of numbers and trying to embed the parameter with the number table but i am nit getting the option for embedding the parameter. Please help.

 

I am using vertica as database.

1 REPLY 1
Anonymous
Not applicable

Hi @sahubibhuti45 ,

To enable dynamic data retrieval based on user input, you can use the parameterisation feature of Python in SQL query execution. This approach not only makes the query dynamic, but also enhances security by preventing SQL injection. Here is a brief step-by-step guide to help you solve the problem:

1. First, make sure there is a mechanism to capture the input of the number of rows the user wishes to retrieve. This can be done with a simple input function in Python.

 

user_limit = input("10")

 

2. Next, parameterise the SQL query using this input.

 

cursor = conn.cursor()
query = "SELECT * FROM table LIMIT ?"
cursor.execute(query, (user_limit,))
rows = cursor.fetchall()

for row in rows:
    print(row)

 

By performing these steps, you can make restrictions in SQL queries dynamic based on user input.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.