Skip to content

get_raw_sql

Execute SELECT queries against your CRM data.

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.

ParameterTypeRequiredDescription
sqlstringYesSQL query to execute (SELECT only)

The local database contains:

TableDescription
contactsAll contacts with email and full properties as JSON
companiesAll companies with domain and full properties as JSON
dealsAll deals with name and full properties as JSON
contact_companyContact to company associations
deal_contactDeal to contact associations
deal_companyDeal to company associations

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,
email
FROM contacts
WHERE json_extract(properties, '$.lifecyclestage') = 'customer'
LIMIT 10

Deals closing this month over $50k:

SELECT dealname,
json_extract(properties, '$.amount') as amount,
json_extract(properties, '$.closedate') as close_date
FROM deals
WHERE 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 company
FROM contacts c
JOIN contact_company cc ON c.id = cc.contact_id
JOIN companies co ON cc.company_id = co.id
WHERE json_extract(co.properties, '$.industry') = 'Healthcare'

Deals with no associated contacts:

SELECT d.dealname
FROM deals d
LEFT JOIN deal_contact dc ON d.id = dc.deal_id
WHERE dc.contact_id IS NULL

Pipeline value by deal stage:

SELECT json_extract(properties, '$.dealstage') as stage,
COUNT(*) as deal_count,
SUM(json_extract(properties, '$.amount')) as total_value
FROM deals
GROUP BY stage
  • 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