Running SQL queries
Whale also enables users to run queries from command-line, against both plain SQL files as well as within markdown files, enabling notebook-style behavior.
Supported connections: BigQuery, Postgres, Presto, Redshift, Snowflake
Executing SQL files
Whale exposes a direct line into SQLAlchemy
against connections defined in ~/.whale/config/connections.yaml
through the wh run
command.
If the -w
flag is not given, the first warehouse in your connections.yaml
file will be used.
If there are multiple warehouses with the same warehouse_name
the credentials from the first matching warehouse_name
encountered will be used.
Note: this only works for (a) direct connections to warehouses (not the Hive metastore) and (b) connections where permissions allow for query runs.
Jinja templating
wh run
also supports Jinja2 templating -- for more information on how to set this up, see Jinja2 templating.
Saving results as comments
If you'd like to store your results automatically as comments within your .sql
file, you can add --!wh-run
to any SQL file (on its own line) and any wh run
execution will automatically string replace this line with the results of the query execution.
For example, the following sql file
would, upon execution using wh run
, would be overwritten as:
Running SQL blocks within markdown files
The wh run
command can also be used against files with the .md
or .markdown
extension, to enable more advanced Jupyter-notebook style behavior within your IDE.
Any block (```sql) containing --!wh-run
will flag said block will:
Flag this block for execution when
wh run
is called on this file.Upon execution, replace the line containing
--!wh-run
with a block of results.
This behavior is very similar to the execution within SQL files as shown above, but enables execution of SQL query blocks alongside context written in Markdown.
For instance, the following Markdown file
Or if installed via Homebrew:
Vscode
TODO
Last updated