# TD Toolbelt Job and Query Command Reference The [TD Toolbelt Reference](https://api-docs.treasuredata.com/en/tools/cli/api/#td-toolbelt-reference) and [additional TD Toolbelt documentation](https://api-docs.treasuredata.com/en/tools/cli/quickstart/#td-toolbelt-quickstart) can be found on the [Treasure Data Developer Portal](https://api-docs.treasuredata.com/). * [TD Query](#td-query-sql) * [Usage](#usage) * [Options](#options) * [Examples](#examples) * [TD Jobs](#td-jobs) * [Usage](#usage-1) * [Options](#options-1) * [TD Job ](#td-job-job_id) Typically, when using the TD Toolbelt to run a query you want to wait for the job to complete. If you issue a query *without* using the -w option, the command ends immediately after submitting the job. * [TD Query](#td-query-sql) * [Usage](#usage) * [Options](#options) * [Examples](#examples) * [TD Jobs](#td-jobs) * [Usage](#usage-1) * [Options](#options-1) * [TD Job ](#td-job-job_id) # td query [sql] ## Usage ```bash $ td query [sql] ``` ## Options ```bash options: -d, --database DB_NAME use the database (required) -w, --wait[=SECONDS] wait for finishing the job (for seconds) -G, --vertical use vertical table to show results -o, --output PATH write result to the file -f, --format FORMAT format of the result to write to the file (tsv, csv, json, msgpack, and msgpack.gz) -r, --result RESULT_URL write result to the URL (see also result:create subcommand) It is suggested for this option to be used with the -x / --exclude option to suppress printing of the query result to stdout or -o / --output to dump the query result into a file. -u, --user NAME set user name for the result URL -p, --password ask password for the result URL -P, --priority PRIORITY set priority -R, --retry COUNT automatic retrying count -q, --query PATH use file instead of inline query -T, --type TYPE set query type (hive, presto) --sampling DENOMINATOR OBSOLETE - enable random sampling to reduce records 1/DENOMINATOR -l, --limit ROWS limit the number of result rows shown when not outputting to file -c, --column-header output of the columns' header when the schema is available for the table (only applies to json, tsv and csv formats) -x, --exclude do not automatically retrieve the job result -O, --pool-name NAME specify resource pool by name --domain-key DOMAIN_KEY optional user-provided unique ID. You can include this ID with your `create` request to ensure idempotence --engine-version ENGINE_VERSION EXPERIMENTAL: specify query engine version by name ``` ## Examples For example, use the -w option: `$ td query -w -d testdb "SELECT COUNT(1) FROM www_access"` `Job 702 is started.` If you issue a query *without* using the -w option, the command ends immediately after submitting the job. For example: `$ td query -d testdb "SELECT COUNT(1) FROM www_access"` `Job 704 is started.` `Use 'td job 704' to show the status.` You can output the job results into local disk as CSV format, instead of STDOUT. `$ td query -o test.csv --format csv -w -d testdb 'SELECT COUNT(1) FROM www_access'` `Status : success` `Result : written to test.csv in csv format` # TD Jobs The td jobs command lists your submitted jobs. The most recent 20 jobs are shown by default. ## Usage ```bash $ td job:list [max] ``` ## Options ```bash options: -p, --page PAGE skip N pages -s, --skip N skip N jobs -R, --running show only running jobs -S, --success show only succeeded jobs -E, --error show only failed jobs --slow [SECONDS] show slow queries (default threshold: 3600 seconds) -f, --format FORMAT format of the result rendering (tsv, csv, json or table. default is table) ``` | **command example** | **to view** | | --- | --- | | $ td jobs -p 0 | the most recent 20 jobs | | $ td jobs -p 1 | jobs 21-40 | | $ td jobs -p 2 | jobs 41-60 | # td job The command shows a specific job’s detailed information. ```bash $ td job 10349872 ``` For example: ![](/assets/image-20190829-231407.6d1b7e391cfa346a8c394174935014e92f2251d179ad23eca546ed3a37fff8a4.60bcc915.png)