Creating a query

To create a query, we can click on Create | Query from the top menu, which will take us to the create the New Query screen.

For this example, we will be using Redash's internal Data Source, called Redash metadata.

Select it using the Data Source selector (element #2 in the query editor overview chapter), and you should see that the Schema Browser refreshes with the updated schema (element #3 in the query editor overview chapter).

Now, let's create a simple query to see all the dashboards that are available in the system (without modifying anything else, and without saving anything, just to get a feeling of how it works).

Type select * from dashboards  in the query editor window (element #4 in query editor overview chapter), and click on the Execute button.

We should now see that the query executes and returns results into the results visualization panel (element #5). The Results Data menu (element #6) and Last Updated Info (#7) should also be updated now:

We've seen how the query executes and how the results are displayed, suppose we've decided that we need to do something different, like check how many queries there are per Data Source. Let's change the query to fetch what we need, and change the query name to something more meaningful (as well as the query description).

So, the new query is (note the join to bring the Data Source name instead of id) as follows:

select count(*),data_sources.name from queries,data_sources where 
queries.data_source_id = data_sources.id group by data_sources.name

We have changed the query name to Queries per Datasource and the description to Number of queries per Datasource. Click on Format SQL (inside the query editor window) to arrange the SQL in a more convenient way.

Click on Execute to validate that the query we wrote doesn't have syntax errors and that we have the data that we need.

Then, click on Save to save the query. You should be able to get the following notification that your query was saved successfully:

Note the text Unpublished next to the query name, as well as the Publish button on the right-hand part of the screen.

There are two states for a saved query: Published and Unpublished. By default, the query starts as Unpublished (right after you save it for the first time).

An Unpublished state means that no one can see the query except the user who has created it (in All queries/my queries or search results). In addition, this means that you can't include unpublished query visualizations in dashboards, or use that query in alerts.

In order to move the query into a Published state, simply click on the Publish button on the right-hand part of the screen (don't worry you can always unpublish in the same manner whenever you wish).

Clicking on the star (to the left of the query name) will add the query to favourites (we can filter favourite queries in the Query Listing page)

Clicking on +Add tag (to the right of the query name) will open a pop-up menu where we can add tags for queries. The usage of tags is similar to #hashtags on the internet, and we can later filter queries by tags, for easier and faster access to the desired query.

The Star and Tag options are depicted in the following image:

Useful keyboard shortcuts:

Ctrl/Cmd + S: Saves the query 
Ctrl/Cmd + Enter: Executes the query
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset