SQL Queries
PushMetrics comes with a powerful SQL editor that allows querying almost any SQL database.
It can be used to both receive data and write data to the database.
Query results data can be used in subsequent tasks.
Creating SQL Queries
SQL Editor
The SQL Editor has the following inputs:
- Query Name: Used for referencing the query and its results
- Database Connection: Select which database the query should run against
- SQL code: Write your SQL statement. Supports Jinja templating, e.g. a parameter value can be used inside the SQL statement like this:
{{ parameter_1 }}
- Limit: Visual interface to apply row limits to queries
Data Explorer
In the left sidebar, you can explore the database's contents like schemas, tables, and columns - making it easier to develop your SQL queries.
When hovering over a table name, you can also preview 100 rows of any table and copy a SELECT *
statement to your clipboard.
Execution
To execute a query, simply hit the Play button or use the keyboard shortcut ⌘ + enter
.
Jinja Preview
You can create dynamic queries using Jinja templating syntax.
This is useful to parameterize queries, use loops or if/else statements in your SQL statements.
You can easily preview the rendered query by clicking on the {{
button:
Query Results
Query results are displayed below the SQL Editor.
- You can sort columns
- You can create a chart from the results data
- You can check the details of the run
</>
- You can download the data as CSV or XLSX
Results History
PushMetrics has a useful feature that keeps a history of your last query runs, so you can compare results between multiple run easily.
Referencing Queries and Results Data
You can use both the query statement and the results data in other tasks using the following methods:
Method | Description |
---|---|
query_name |
returns the query as a string Example Usage: Example Output: |
.data |
returns the most recent query result as a dictionary Example Usage: Example Output: |
.data[row_index] |
returns a single row of the most recent query result Example Usage: Example Output: |
.data[row_index].column_name |
returns a single cell value of the most recent query result Example Usage: Example Output: |
.export(filename, file_format='csv', csv_delimiter=' , ' , public=false) |
generates a .csv or .xlsx file from the most recent results and returns a secure file URL. The file can be made public. Options: Example Usage: Example Output: |