OdyDocs

Database: SQL referencebeta

The read-only SQL that POST /data/query accepts: the two tables, the supported keywords and functions, the limits, and examples.

POST /v1/api/data/query runs one read-only SELECT over a workspace's Database. This page lists what the statement can contain.

Switched on per workspace

The Database is in beta and Ody turns it on for one workspace at a time. Until it is on for yours, the endpoint returns 409 failed_precondition.

#How a query runs

Your statement is not sent to the database as written. Ody reads it, checks every table and column name against your workspace's columns, and builds its own query in which every value is a bound parameter. Three things follow from that:

  • Only what is listed on this page works. Anything else fails with 400 invalid_argument and a message that says what to change and where in the statement.
  • A query can only read. There is no statement that writes, and the query also runs in a read-only transaction.
  • A query can only see your workspace. No other table exists for it.

The scope is contacts:read.

#Tables

Call GET /data/schema for the exact list in your workspace, with the type of every column and how to write its name.

#contacts

One row per contact. Every contact is here, including contacts with no values.

ColumnType
ididThe contact's id
nametextFirst and last name together
first_name, last_name, companytext
phonetextThe contact's first phone number, E.164
emailtextThe contact's first e-mail address
tagslistTest one with 'vip' = ANY(tags)
created_attimestampWhen the contact was created
job_title, headline, website, linkedin_url, company_domain, company_linkedin_url, secondary_phonetextOnly where AI Contact is on
address_street, address_city, address_state, address_postal_code, address_countrytextOnly where AI Contact is on. Stored as given: a state can be TX or Texas
phone_line_type, phone_carrier, caller_id_name, ai_notestextOnly where AI Contact is on. phone_line_type is mobile, landline, voip, toll_free or unknown
one per Database columnby columnNamed by the column's key

How each Database column appears:

Column typeSQL typeNotes
text, selecttext
numbernumber
datedate
booleanbooleanEmpty is NULL
multi_selectlistTest one choice with 'Voice' = ANY(interests). A list cannot be grouped.
signalbooleanNever NULL: false until the contact said it
signal, a second columnnumber<key>_count: the number of conversations it came up in

A column whose key is the name of one of the contact's own fields is written data_<key>: a Database column named "Company" is data_company. The card field names in the table above are set aside on every workspace, with or without AI Contact, so a Database column named "Job title" is always data_job_title and a saved query keeps its meaning. A key that is an SQL keyword or starts with a digit is written in double quotes: "order", "2nd_phone". GET /data/schema gives the right spelling in each column's sql field.

Columns appear on their own

Ody adds columns from conversations, so contacts can have a column today that it did not have last week. A query that names its columns keeps working. SELECT * returns whatever columns exist, and is refused on a table with more than 50 columns.

#observations

One row per thing Ody heard a contact say: the history behind the cells Ody filled. Values that a person or the API wrote are not here.

ColumnType
idid
contact_ididJoins to contacts.id
column_keytextThe key of the column the value is for
column_nametextThe name of that column
valuetextWhat was heard, as text. Several choices are joined with commas.
observed_attimestampWhen the conversation happened
channeltextcall, ai_call, voicemail, text or greeting
directiontextinbound or outbound, when known
confidencenumberHow sure Ody was, from 0 to 1
appliedbooleanWhether this observation changed what the cell shows

The contact's words are not in this table. The quote is shown in the app.

#What a statement can contain

ClausesSELECT, SELECT DISTINCT, FROM, JOIN … ON, WHERE, GROUP BY, HAVING, ORDER BY … ASC / DESC [NULLS FIRST / LAST], LIMIT, OFFSET, AS
Tablescontacts, observations, or the two joined: contacts JOIN observations ON contacts.id = observations.contact_id
Comparisons=, <> (or !=), <, <=, >, >=, BETWEEN … AND …, IN (…), NOT IN (…), LIKE, ILIKE, IS NULL, IS NOT NULL, IS TRUE, IS NOT TRUE, IS FALSE
LogicAND, OR, NOT, parentheses
Lists'value' = ANY(column)
Arithmetic+ and - on numbers
Totalscount(*), count(x), count(DISTINCT x), sum, avg, min, max
Functionslower, upper, length, round, coalesce, date_trunc, now(), current_date
DatesCompare a date or timestamp with a string: renewal_date < '2027-01-01'. Add or subtract a period: now() - INTERVAL '30 days', current_date + INTERVAL '2 weeks'. date_trunc takes hour, day, week, month, quarter or year.
GroupingBy a column, by an expression, by an output name, or by position: GROUP BY 1

Keywords and names are not case-sensitive. One trailing semicolon is allowed.

#Not supported

  • Any statement other than SELECT
  • Subqueries, WITH, UNION, EXISTS
  • CASE
  • Window functions and FILTER
  • LEFT, RIGHT, FULL and CROSS joins, and joining a table to itself
  • Multiplication and division
  • Any function not listed above
  • Comments

For anything heavier, export the rows with GET /data/rows and query them in your own database.

#Behaviour to know

  • Times are UTC. date_trunc('day', observed_at) cuts at midnight UTC, and now() and current_date are UTC.
  • Empty values sort last, in both directions. Write NULLS FIRST to put them first.
  • A list column cannot be grouped. To count contacts per choice of a multi_select column, use GET /data/columns/:column/summary.
  • Output columns without a name are called column_1, column_2, … by position. Give them names with AS.
  • Text comparison is exact. plan = 'pro' does not match Pro. Use lower(plan) = 'pro' or ILIKE.

#Limits

Length of the statement4,000 characters
Rows returned by one call1,000. truncated: true in the response means more rows matched.
Items in SELECT50
Database columns used in one statement40
Values in one IN (…)200
Running time5 seconds. A statement that takes longer is stopped and returns 400; add a filter or a smaller LIMIT.

To read more than 1,000 rows, page with LIMIT and OFFSET and a stable ORDER BY:

Text
SELECT id, name, plan FROM contacts ORDER BY id LIMIT 1000 OFFSET 1000

Calls count toward the rate limit like any other request.

#Examples

Contacts per plan, largest first:

Text
SELECT plan, count(*) AS contacts
FROM contacts
GROUP BY plan
ORDER BY contacts DESC

Pro contacts with a budget of at least 500 whose renewal is in the next 30 days:

Text
SELECT name, phone, budget, renewal_date
FROM contacts
WHERE plan = 'Pro'
  AND budget >= 500
  AND renewal_date BETWEEN current_date AND current_date + INTERVAL '30 days'
ORDER BY renewal_date

Contacts who asked about pricing more than once (asked_about_pricing is a signal column):

Text
SELECT name, phone, asked_about_pricing_count
FROM contacts
WHERE asked_about_pricing AND asked_about_pricing_count > 1
ORDER BY asked_about_pricing_count DESC

New contacts per month:

Text
SELECT date_trunc('month', created_at) AS month, count(*) AS contacts
FROM contacts
GROUP BY 1
ORDER BY 1

Contacts tagged vip who are interested in Voice (interests is a multi_select column):

Text
SELECT name, company
FROM contacts
WHERE 'vip' = ANY(tags) AND 'Voice' = ANY(interests)

What Ody learned this month, by column and channel:

Text
SELECT column_name, channel, count(*) AS heard
FROM observations
WHERE observed_at >= date_trunc('month', now())
GROUP BY column_name, channel
ORDER BY heard DESC

Everything heard from one company's contacts in the last week:

Text
SELECT contacts.name, observations.column_name, observations.value, observations.observed_at
FROM contacts
JOIN observations ON contacts.id = observations.contact_id
WHERE contacts.company ILIKE '%brightline%'
  AND observations.observed_at >= now() - INTERVAL '7 days'
ORDER BY observations.observed_at DESC

#Run a query

curl https://api.ody.co/v1/api/data/query \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "sql": "SELECT plan, count(*) AS contacts FROM contacts GROUP BY plan ORDER BY contacts DESC" }'
Response
{
  "columns": [
    { "name": "plan", "type": "text" },
    { "name": "contacts", "type": "number" }
  ],
  "rows": [
    { "plan": "Pro", "contacts": 701 },
    { "plan": "Free", "contacts": 455 },
    { "plan": null, "contacts": 628 }
  ],
  "rowCount": 3,
  "truncated": false
}

The TypeScript and Python calls need v0.10.0 of the SDKs, which is not on npm or PyPI yet. With v0.9.0, use the cURL call.

#From an AI assistant

The MCP server has the same query as the tool query_data, and describe_data for the column names. An error comes back as a sentence the assistant can act on, for example:

Text
There is no column "plam". Columns: id, name, first_name, last_name, company, phone, email, tags, created_at, plan, seats, renewal_date

See MCP tools.

Last updated Sun Nov 29 2026 00:00:00 GMT+0000 (Coordinated Universal Time)Something wrong on this page? Tell us