Classify a million rows in Postgres, cheaply
Yes, you can classify a text column in SQL without standing up a Python service, and it can be cheap enough to run across a million rows. The bill depends on the model, the length of each row, and whether you re-send work you have already paid for.
Published November 22, 2026. che.sh figures are measured decision-step averages from che.sh/models as of November 29, 2026, 10:56 PM, America/New_York, current versions, cache hits excluded. They are not a quote for your table.
The short answer
A million classifications used to mean a notebook, a job queue, and a surprise invoice. The new path is a SQL function over a column: classify, filter, or route each row in place. Snowflake, Databricks, BigQuery and MotherDuck all ship some version of this. The catch is lock-in, token billing, and full refreshes that rebill every row.
On our public checks, the measured average decision-step cost for a capable model is a few hundredths to a few tenths of a millidollar per run. Multiplied out:
As of November 29, 2026, 10:56 PM, America/New_York, decision steps only, measured average cost times one million runs:
| Model | Right | Lower bound | Median | Avg / run | Per million runs | Runs in the average |
|---|---|---|---|---|---|---|
| groundhog 1 | 187/191 | 94.7% | 526 ms | $0.00007884 | $78.84 | 191 |
| jev 1.14 | 226/233 | 93.9% | 336 ms | $0.00010414 | $104 | 233 |
| jev 1.13 | 187/193 | 93.4% | 321 ms | $0.0001144 | $114 | 193 |
| pplx flash 1.2 | 27/28 | 82.3% | 394 ms | $0.0000221 | $22.10 | 28 |
| d1.1 | 30/30 | 88.6% | 394 ms | $0.00003603 | $36.03 | 30 |
| joey-1 | 112/143 | 70.9% | 343 ms | $0.00001534 | $15.34 | 143 |
2928 scored runs in the current window, about $0.577 spent on decision steps, first run November 22, 2026, 4:53 AM, America/New_York. Extract-step cost on trees that read a document is not in these averages. Source: che.sh/models.
Two cautions. First, some of those rows have only a couple of dozen runs, so the lower bound is the number to trust, not the raw share. pplx flash 1.2 is the dashboard’s cheapest “still right” model in this snapshot, but it has been scored on fewer checks than jev or groundhog. Second, joey-1 is the cheapest of the set and just as fast, and it misses often enough that we would not send a million rows through it just because the unit price looks good.
What other platforms charge
These are vendor figures, not our measurements, current as we read them on November 22, 2026.
- MotherDuck published a 100,000-row AG News run for
prompt_jev(): 40 seconds, $0.50, 89% accuracy, against a much slower and more expensive GPT-5.6 Terra baseline. Official billing is input tokens only; their pricing page lists 19,047,619 input tokens per $1 AI Unit, with output free. See the launch post and MotherDuck pricing. Criteria must be query constants, and by default a session cap of 10 AI Units sits on the function. - Databricks publishes US East estimates for AI Functions:
ai_classifyon short text at $0.21–$0.42 per 1,000 inputs, andai_decideticket routing at $0.03–$0.04 per 1,000, plus the warehouse or job compute. Source: databricks.com/product/pricing/ai-functions. - Snowflake Cortex bills AI functions in credits per token. For
AI_CLASSIFY, input and output are both billable, and labels, descriptions and examples count as input on every row, not once per query. Warehouse compute is extra. Official notes: docs.snowflake.com/en/user-guide/snowflake-cortex/aisql-cost. Credit-to-dollar rates live in Snowflake’s Service Consumption Table; we are not reprinting a third-party conversion here. - BigQuery’s classify and generate functions incur Gemini / Agent Platform token charges on top of bytes scanned. An “optimized” mode can label a sample with the full model and run the rest on a distilled model, which is a real cost lever, described in dbt’s 2026 writeup.
DuckDB has community extensions in this neighborhood too (FlockMTL’s llm_filter / llm_complete, and a community ai_classify). They are useful locally. They are not Postgres, and you bring your own model keys.
The bill that surprises people
The unit price is only half of it. The other half is how often you pay it. A forgotten LIMIT on an LLM SQL function has been a running joke since MotherDuck’s original prompt() post in October 2024 (HN thread). dbt’s advice for BigQuery AI functions is the same idea in production form: never let an AI call live inside a full refresh; materialize incrementally so only new rows go to the model.
A cache helps when the same text comes back. rvbbit writes a receipt for each operator call (rvbbit.receipts: model, inputs, output, tokens, cost). Repeated work can be answered from cache. che.sh demo checks deliberately skip that cache, so the public scores stay honest. Your own trees, and SQL you run in your own Postgres, can use it. That is how a million-row backfill stays a backfill, not a monthly ritual.
Postgres, not only a warehouse
Warehouse AI functions are convenient if your data already lives there. If it lives in Postgres, you should not have to ship it out. rvbbit’s functions are first-class SQL: the planner sees them, they compose with ordinary JOIN, WHERE and GROUP BY, and a tree is just a value you pass into rvbbit.decision_tree.
WITH inputs(id, body) AS (
-- swap this for: SELECT id, body FROM support_tickets
VALUES (1, 'you charged me twice, fix it')
),
tree AS (
SELECT rvbbit.choice_branch(
'What does the customer need help with?',
jsonb_build_object(
'billing', 'Invoices, charges, payments or refunds',
'scheduling', 'Appointments, dates or availability',
'other', 'Anything else, or unclear'),
jsonb_build_object(
'billing', rvbbit.leaf('refund review'),
'scheduling', rvbbit.leaf('send to scheduling'),
'other', rvbbit.leaf('a human should look'))) AS t
)
SELECT i.id, d ->> 'label' AS decision
FROM inputs i, tree,
LATERAL rvbbit.decision_tree(i.body, tree.t, 16) AS d;
That is the same surface the che.sh canvas emits when you press s. You can also define your own typed operator with rvbbit.create_operator and call it like any other function; rvbbit documents this under Semantic SQL at rvbbit.ai/docs/semantic-sql/.
A note on pgai
For a while, the obvious Postgres path was Timescale’s pgai extension: SQL-callable helpers such as ai.openai_chat_complete. On Tiger Cloud, those in-database LLM calls were removed on June 30, 2026. The current guidance is to call the provider SDK from application code and keep embeddings in Postgres for search. Official note: tigerdata.com/docs/deploy/tiger-cloud/vectorizer-deprecation.
Ryan looked at an earlier pgai design and did not like it: it did not read like SQL, it did not compose, and at the time it felt like calling an external Python function. That was his read then. We have not re-audited later revisions of the code, and the June 2026 removal is the fact that matters for anyone still searching for “pgai” as a classify-in-SQL answer. PostgresML is a different thesis again: run models inside the database, which can be the right tool, but it is not a cheap, composable decision-and-extract function with a public scoreboard.
How we handle it with rvbbit and che.sh
Draw a tree at che.sh, try it on a row, then run the exported SQL over your table. Or start from a live demo and press s: /demo for refund triage, /scam for a message, /router to hop to the matching check. The cost and accuracy of the models behind those trees are public at /models. che.sh itself is another interface, not a second engine: decisions still run on rvbbit, with Jev and other decision models reached through OpenRouter.
If you already have dbt on Postgres, the same incremental-model habit applies. Call the function only for new or changed rows, store the label, and leave yesterday alone.
FAQ
How much does it cost to classify a million rows?
It depends on the model and the length of each row. On che.sh/models, measured average decision-step cost (current versions, cache excluded) works out to about $16 to $127 per million runs for the models we highlight, not including any extract step. Warehouse classify functions are priced separately and often also bill warehouse compute.
Will a SQL classify function rebill every row on every run?
It can, if you full-refresh a table or skip a cache. dbt guidance for BigQuery AI functions is to materialize incrementally so only new rows are sent. rvbbit records receipts and can answer a repeated call from cache; che.sh demo checks deliberately skip that cache so the public scores stay honest.
Can I do this in Postgres, or only in a cloud warehouse?
You can do it in Postgres. che.sh trees export as rvbbit SQL: rvbbit.decision_tree, rvbbit.choice_branch, rvbbit.branch, rvbbit.leaf, and rvbbit.clover_extract_fields. Snowflake, Databricks, BigQuery and MotherDuck offer similar primitives, locked to those platforms.
What happened to pgai's SQL LLM functions?
On Tiger Cloud, in-database LLM SQL helpers were removed on June 30, 2026. Tiger Data now tells people to call provider SDKs from application code and keep vectors in Postgres. Ryan looked at an earlier pgai design and found it did not read like SQL, did not compose, and felt like calling an external Python function; that was his read at the time, and we have not re-audited later revisions.
Sources
- che.sh/models and che.sh/api/scoreboard, as of November 29, 2026, 10:56 PM, America/New_York
- MotherDuck, Introducing prompt_jev() and pricing
- Databricks AI Functions pricing
- Snowflake Cortex AISQL cost notes
- dbt Labs, generative AI in a dbt pipeline
- Hacker News, MotherDuck prompt() (October 17, 2024)
- Tiger Cloud, pgai LLM SQL deprecation (removed June 30, 2026)
- rvbbit Semantic SQL