Creating your first query

Click on Create and select query from the drop-down menu. This will bring you to the query editor window, where the first thing you will have to select is the Data Source of the query (the Data Source selector is on the top-left-hand side of the window, right below QueryName, which in the case of creating a new query will be New Query). In this example, we will use one of the Data Sources we've just created (Redash Meatadata or quickstart_1):

After selecting the desired Data Source (in our case, Redash Metadata), we should see the schema (the available tables and their structure) on the left-hand side below the Data Source selector:

Not all the Data Sources have schemas available.
If you used a URL Data Source, you won't see the schema.

We can then start typing our query into the query editor window (the main section right in the middle of the screen).

Autocomplete is available by default, and is presented automatically (unless we have lot of tables/columns, in which case you have to hit Ctrl + Space).

For the next example, we will use the visualizations table, which represents visualizations that are created in Redash.

The table has the following columns: id, type, query_id, name, description, options, created_at, updated_at.

In our example, the query is as follows (for SQLish datasources):

select type, count(*) from visualizations group by type order by count(*); 

If you used our alternative URL Data Source, the query is as follows:

sample_url_datasource.json

This will show us the distribution of the visualization types.

After we have finished writing the query, we can execute it to see the results it returns:

A new query always starts in an Unpublished state, meaning that no one except you can see it. After saving the query, publish it to allow others to see it.

If you want to get a preview of the query results (and check whether this dataset is what you had in mind), click on the Execute button. Once you're happy with the query and the results, and you want to add a visualization, save the query.

After the query has finished executing, we can see the results in the form of a table right below the query window:

At the bottom of the page, the following metadata will be present:

Row count, query runtime, and last update time.

Also note that after we save the query, it is possible to share it through a URL (in the form of http://$REDASH_IP_OR_HOSTNAME/queries/$QUERY_ID). In our example, the URL is http://54.159.153.159/queries/5, and if you open it, you should see the query results in the form of a table. If you want to edit the query, you need to click on Edit Source:

..................Content has been hidden....................

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