get_raw_sql
Execute SELECT queries against your CRM data.
Description
Section titled “Description”The get_raw_sql tool runs SQL queries against your local HubSpot database. Only SELECT queries are allowed - your CRM data can never be modified.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
sql | string | Yes | SQL query to execute (SELECT only) |
Database Schema
Section titled “Database Schema”The local database contains:
| Table | Description |
|---|---|
contacts | All contacts with email and full properties as JSON |
companies | All companies with domain and full properties as JSON |
deals | All deals with name and full properties as JSON |
contact_company | Contact to company associations |
deal_contact | Deal to contact associations |
deal_company | Deal to company associations |
Querying Properties
Section titled “Querying Properties”All HubSpot properties are stored as JSON. Use json_extract() to query them:
SELECT json_extract(properties, '$.firstname') as first_name, json_extract(properties, '$.lastname') as last_name, emailFROM contactsWHERE json_extract(properties, '$.lifecyclestage') = 'customer'LIMIT 10Example Queries
Section titled “Example Queries”Deals closing this month over $50k:
SELECT dealname, json_extract(properties, '$.amount') as amount, json_extract(properties, '$.closedate') as close_dateFROM dealsWHERE json_extract(properties, '$.amount') > 50000 AND json_extract(properties, '$.closedate') LIKE '2026-02%'Contacts at healthcare companies:
SELECT c.email, json_extract(c.properties, '$.firstname') as name, json_extract(co.properties, '$.name') as companyFROM contacts cJOIN contact_company cc ON c.id = cc.contact_idJOIN companies co ON cc.company_id = co.idWHERE json_extract(co.properties, '$.industry') = 'Healthcare'Deals with no associated contacts:
SELECT d.dealnameFROM deals dLEFT JOIN deal_contact dc ON d.id = dc.deal_idWHERE dc.contact_id IS NULLPipeline value by deal stage:
SELECT json_extract(properties, '$.dealstage') as stage, COUNT(*) as deal_count, SUM(json_extract(properties, '$.amount')) as total_valueFROM dealsGROUP BY stageSecurity
Section titled “Security”- Only SELECT queries are allowed
- Dangerous keywords (INSERT, UPDATE, DELETE, DROP, etc.) are blocked
- Results limited to 1,000 rows by default
- Query timeout: 30 seconds