Overview
Theexecute_query tool executes SQL queries against the GDELT GDELT database database, returning data for research, analysis, and iterative exploration.
This tool is designed for ad-hoc research and Q&A workflows. For creating alerts or saved queries, use
present_sql instead.When to use
Useexecute_query for:
- Ad-hoc research questions
- Iterative data exploration
- Testing queries before saving
- Real-time analysis and insights
- Answering specific user questions
Prerequisites
Parameters
Complete SELECT query to execute on GDELT database GDELT database.Query requirements:
- Must include date filter (e.g.,
WHERE day >= today() - INTERVAL 7 DAY) - Must include LIMIT clause (maximum 1000 rows)
- Must select source URL column (
source_urlordocument_identifier) - Must use valid table and column names from schemas
Concise title for this query (e.g., ‘Climate Protests in Europe’, ‘US Political Events’).Example: “Recent US Political Events”
Plain language description of what this query asks and returns.Example: “Finds all political events in the United States over the last 7 days with actor names and event codes”
Response
Array of result objects. Each object contains columns as specified in your SELECT clause.
Number of rows returned by the query.
Query execution time in seconds.
The executed SQL query (echoed back for reference).
The query title (if provided).
The query description (if provided).
Error message if query failed.Common errors include:
- Invalid column names
- Missing required filters
- Syntax errors
- Permission issues
Helpful suggestion if query failed.Typically recommends calling
prepare_gdelt_query to verify schemas.Usage examples
Query workflow
1
Prepare query context
Call
prepare_gdelt_query to get schemas and codes.2
Build SQL query
Use the schemas to construct your SELECT query with:
- Correct column names and types
- Required date filter
- Required LIMIT clause (max 1000)
- Source URL column selection
3
Execute and analyze
Call
execute_query and analyze results.Results are returned immediately for iterative exploration.
4
Iterate if needed
Refine your query based on results and execute again.This tool is designed for rapid iteration and exploration.
Validation
The tool automatically validates your query against GDELT requirements:Date filter requirement
Date filter requirement
Rule: All queries must include a date/time filterValid examples:Why: Ensures reasonable query scope and prevents full table scans.
LIMIT clause requirement
LIMIT clause requirement
Rule: All queries must include LIMIT (maximum 1000)Valid examples:Why: Prevents excessive data transfer and timeout issues.
Source URL requirement
Source URL requirement
Rule: Must select Why: Enables citation and fact-checking of results.
source_url or document_identifierValid examples:Performance tips
Error handling
Column does not exist
Column does not exist
Error: “Unknown column ‘xyz’ in ‘field list’”Solution: Call
prepare_gdelt_query to see available columns. Check for typos.Common mistakes:country_codevsactor1_country_codevsaction_geo_country_codesource_urlvsdocument_identifier(different tables use different names)
Table does not exist
Table does not exist
Error: “Table ‘xyz’ doesn’t exist”Solution: Verify table name against the 9 available tables. Use underscore format:
gdelt_events, not gdelt.events.Query timeout
Query timeout
Error: “Query exceeded timeout limit”Solution:
- Reduce date range
- Add more selective filters
- Use pre-aggregated views (mv_event_mention_stats)
- Reduce LIMIT if selecting many columns
Authentication error
Authentication error
Error: “Authentication required” or “Invalid token”Solution: Ensure your bearer token is valid and properly configured. See authentication guide.
Rate limit exceeded
Rate limit exceeded
Error: “Rate limit exceeded”Solution: Wait before retrying. See rate limits in your plan details.
Common query patterns
Event analysis by country and event type
Theme trending over time
Viral events detection
Person mentions with location context
Best practices
Include title and description when appropriate - Helps organize queries and improves UX when creating alerts
Test with small LIMIT first - Start with LIMIT 10-50 to verify results before requesting more
Use appropriate date ranges - Match your date range to your question (7 days for “recent”, 1 day for “today”)
Select only needed columns - Fewer columns = faster queries and smaller responses

