Why not add a new feature about sql query limit and download limit rows?

Hello, everyone, why not add a function to limit the number of rows downloaded by the user and the number of SQL rows returned by the query?

I think this function has a great effect in the query performance and data security of redash. Thanks!

You can implement a limit on the number of rows returned by a query by including the TOP or LIMIT (depending on your data source) keyword in the query. If you want to make this configurable you can add a parameter to set the number of rows as well e.g.

SELECT col1, col2 FROM myTable LIMIT {{ numrows }} ;

Hi @griffinator76, thanks you reply. Your advice is good, but it would be better to consider to add a function to limit.

Can you elaborate on what kind of “function” you’re imagining? A data source level setting for admins? Something users can set themselves?
Different data sources handle query result limiting in different ways, and some don’t support it at all, so what data sources did you have in mind?

The data sources are mainly Postgresql and presto. People can manually click to set the number of rows displayed without sql limit. If you know supset, this feature like that.
image

Agree with @griffinator76 this would be complex to implement across all data sources. But it’s an easy change for Postgres and Presto. Just modify your pg.py file to append LIMIT 1000 to every query or whichever you prefer.