| name | tdx-basic |
| description | Executes tdx CLI commands for Treasure Data. Covers `tdx databases`, `tdx tables`, `tdx describe`, `tdx query`, `tdx auth setup`, context management with profiles/sessions, and output formats (JSON/TSV/table). Use when users need tdx command syntax, authentication setup, database/table exploration, schema inspection, or query execution. |
tdx CLI - Basic Operations
Setup
npm install -g @treasuredata/tdx
tdx auth setup
tdx auth setup --profile production
TDX_API_KEY=your-key-id/your-key-secret
tdx auth
Context Management
Context priority: CLI flags > session > project tdx.json > profile > global config
tdx use database mydb
tdx profile use production
tdx status
tdx unset database
tdx use --clear
Session database eliminates the need for fully-qualified table names across commands:
tdx use database mydb
tdx tables
tdx query "select * from users limit 10"
Profile Management
tdx profile list
tdx profile create staging
tdx profile set database=dev
tdx --profile staging query "..."
Profiles (~/.config/tdx/tdx.json)
{
"profiles": {
"production": { "site": "us01", "database": "analytics" },
"dev": { "site": "jp01", "database": "dev_db" }
}
}
Project Config (tdx.json in project root)
{
"site": "us01",
"database": "customer_analytics",
"parent_segment": "active_users"
}
Core Commands
Databases
tdx databases
tdx databases "prod_*"
tdx databases --json
Sites: us01 (default), jp01, eu01, ap02
Tables
When the target database is known, set context first:
tdx use database mydb
tdx tables
tdx tables "user_*"
tdx tables "mydb.*"
Avoid tdx tables "*.table_name" — cross-database wildcard search is expensive. Set the database context instead.
Schema Inspection
Use tdx describe (or tdx desc) to check table schema:
tdx describe mydb.users
tdx desc users
tdx describe mydb.users --json
tdx show mydb.users --limit 10
Queries
Query output is truncated to 40 rows by default. Use --limit to return more:
tdx query "select * from users" --limit 100
tdx use database mydb
tdx query "select * from users limit 10"
tdx query "select * from mydb.users limit 10"
tdx query -f query.sql
tdx query -
echo "select 1" | tdx query -
tdx sg sql "Segment Name" | tdx query -
Output Formats
tdx databases --json
tdx query "..." --jsonl
tdx databases --tsv
tdx databases --output out.json
Global Options
tdx <command> --help
--profile <name>
--json / --jsonl / --tsv
--output <file>
--dry-run
TD-Specific Conventions
- Table naming:
database_name.table_name
- Time column: Unix timestamp (seconds since epoch), not datetime
- Time filtering: Use
td_interval(time, '-1d/now') or td_time_range(time, 'start', 'end') for partition pruning
- Timezone: UTC default; use
td_interval(time, '-1d', 'JST') for Japan
select time, from_unixtime(time) as datetime from mydb.events limit 1
Project Folder Structure
tdx organizes resources into conventional folders:
my-project/
├── tdx.json # Project config (site, database, contexts)
├── parent_segments/ # Parent segment definitions
│ ├── customer-360.yml
│ └── demo-audience.yml
├── segments/ # Child segments and journeys (per parent)
│ └── customer-360/
│ ├── tdx.json # { "parent_segment": "Customer 360" }
│ ├── high-value.yml # Segment
│ ├── onboarding.yml # Journey (type: journey)
│ └── marketing/ # Folder organization
│ └── newsletter.yml
├── workflows/ # Digdag workflow projects
│ └── daily-etl/
│ ├── tdx.json # { "workflow_project": "daily-etl" }
│ └── main.dig
└── agents/ # LLM agents (per project)
└── my-llm-project/
├── tdx.json # { "llm_project": "My LLM Project" }
├── support-agent/
│ ├── agent.yml
│ └── prompt.md
└── knowledge_bases/
└── faq.yml
Each tdx.json stores context for its directory—commands run from any subdirectory use the nearest config.
Resources