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

Feature: support for query parameters #363

Merged
merged 4 commits into from
Jan 27, 2015
Merged

Conversation

arikfr
Copy link
Member

@arikfr arikfr commented Jan 27, 2015

This is initial work on support for query parameters. Currently it works by detecting mustache style parameters in the query text, and merging them with values from the URL query string.

No UI yet, you have to use the query string.

image

@arikfr
Copy link
Member Author

arikfr commented Jan 27, 2015

@sidazhang @jeremi FYI, this is going to be released soon (you were asking about this in the past).

@arikfr arikfr force-pushed the feature/query_parameters branch from 13cc196 to c0c1022 Compare January 27, 2015 08:28
arikfr added a commit that referenced this pull request Jan 27, 2015
@arikfr arikfr merged commit 63274db into master Jan 27, 2015
@sidazhang
Copy link

@arikfr This is awesome. I am very excited to try this out.

And all these commercial vendors dares to charge $1000+ a month?

@arikfr
Copy link
Member Author

arikfr commented Jan 27, 2015

@sidazhang let me know if you need guidance on how to upgrade from your current re:dash version.

@gabrielcrowdtilt
Copy link

Ooohhhh...I'm on v0.5.0+b681 and just demo-ed this. Can it be done with dashboards with charts too?

@arikfr
Copy link
Member Author

arikfr commented Feb 6, 2015

@gabrielcrowdtilt yes. works the same with dashboard/charts.

@arikfr arikfr deleted the feature/query_parameters branch April 1, 2015 14:26
@maflorvega
Copy link

Hi Arik!. I tried to add a table/chart using a query with this solution but the table/chart added doesn't show any results. I guess this is because the dashboard url doesn't have the value parameters needed to executed successfully the query associated with the table/chart. How can I do it correctly?

@arikfr
Copy link
Member Author

arikfr commented Aug 6, 2015

@maflorvega as you figured, you need to pass the parameter(s). You do this the same as you do in the query view: pass it from the URL with the prefix p_. So for example, if the param name is "param" you would pass "p_param=...".

@maflorvega
Copy link

Thanks Arik!!!

@matiascarazzo
Copy link

Arik , do you know if there is any way to set a default value to the parameters?
Maybe use some angular code in a text box? or even in the query itself?

Regards

@arikfr
Copy link
Member Author

arikfr commented Aug 20, 2015

@matiascarazzo not at the moment, but I do want to add this option. Improving the usability of the parameters feature is the next thing I'm going to work on. Next week I'm on vacation, but hopefully I get to work on it the week after when I'm back.

@truclk
Copy link

truclk commented Mar 11, 2016

@arikfr what about using it with api/queries/.../results.json ? I'm trying to build dynamic api to use with my Dashboard UI.

@arikfr
Copy link
Member Author

arikfr commented Mar 11, 2016

@afterlastangel I did some work to prepare support for it, and maybe in the next release it will be possible.

@truclk
Copy link

truclk commented Mar 15, 2016

@arikfr what about widget/virtualization with parameters? I'm going create a chart with date range as parameter, so we need a way add the date range picker. If you didn't have a planing for it, then I could try with the widget then make a pull request.

@arikfr
Copy link
Member Author

arikfr commented Mar 16, 2016

Widgets/visualizations already support parameters, see: demo.redash.io/queries/146/source?p_action=create for example. What's missing is UI and that's planned for one of the next releases.

@truclk
Copy link

truclk commented Mar 16, 2016

@arikfr thank you. I just question about the Widgets UI for parameters, if you didn't implement it yet, I could try to create some for my own using.

@Bitcoyne
Copy link

@arikfr I'm having trouble passing parameters into a column with a string or date data type.

where url param:
?p_account=uk

Error:
column "uk" does not exist in table

When using single quotes in the url param, the url is then encoded:
p_account=%27uk%27

causing a new error:
Error running query: syntax error at or near "uk" LINE 5: and account like 'uk' ^

Any workaround on this?

@rohanpd
Copy link

rohanpd commented Apr 18, 2016

@Bitcoyne in your query you could wrap your parameter in quotes and percentages as follows:

WHERE account = '%{{account}}%'

@ChiragKParmar
Copy link
Contributor

@arikfr I created a user with 'read only' permission on the datasource, but that user was not able to get result by passing query string. is this a known issue?

@arikfr
Copy link
Member Author

arikfr commented Apr 19, 2016

@ChiragKParmar currently it's the intended behavior for two reasons:

  1. With current implementation, we just run a new query generated of the requested one + parameters.
  2. Even when we overcome this (by using the backend support for parameters) there is still the risk of SQL injection to run any query.

Until #2 properly addressed, we can't allow read only users use parameters. :(

@arctica
Copy link

arctica commented Jul 12, 2016

Hi @arikfr

Any update on the GUI part for parameters? It's the last piece in the puzzle for us. Three things would be especially useful:

  • A datepicker (actually two, for ranges)
  • A dropdown select box which could be filled by another query
  • Default values

@sks-369
Copy link

sks-369 commented Nov 14, 2016

Any update on the GUI part of parameters?

@arikfr
Copy link
Member Author

arikfr commented Nov 20, 2016

It's been implemented and released.

On Mon, 14 Nov 2016 at 15:14 sks-369 notifications@github.com wrote:

Any update on the GUI part of parameters?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#363 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEXLDvQpGcNwWiuHfz8BqO6QfjYpWh7ks5q-F5wgaJpZM4DXoIO
.

@ryanmerolle
Copy link

@arikfr

Is the query parameters dropdown select box for available for testing in any particular version yet?

Thanks for all the hard work!

washort pushed a commit to washort/redash that referenced this pull request Apr 30, 2018
washort pushed a commit to washort/redash that referenced this pull request May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.