# ML in SQL: real-time fraud detection

ML in SQL means calling a trained model as a SQL function, next to the data. In Otterstax Enterprise, you put an ONNX model in S3, register it through SQL and call it in any query — for example, to score each transaction from Kafka for fraud in real time.

**Situation:** A trading company detected fraud about 2 hours after it happened.

**With Otterstax:** Transactions stream in from Kafka, and an ONNX model scores each one as a SQL function.

ONNX model as a SQL function · Enterprise:

```sql
SELECT tx_id, fraud_score(tx.*) AS risk
FROM kafka.transactions tx
WHERE fraud_score(tx.*) > 0.9;
```

**Result:** −36.8% — fraud

**Customer:**

- **Trading company:** Fraud detected ~2 hours after it happened → Detection in real time. −36.8% fraud.

## Customer stories

- **Payments company:** ML features waited on multi-step Kafka pipelines → Models in production under 2 s latency, with fewer Kafka and database instances. 30–50% faster ML delivery.

## Less infrastructure. Faster delivery. No lock-in.

### From heavy to light infrastructure

AI workloads multiply data volume. With Otterstax you don’t need a central warehouse or data copies, and you run fewer pipelines and pay for fewer licenses.

- **30–50%** faster time-to-production for ML features (payments company)
- **Fewer Kafka and database instances** after replacing multi-step pipelines (payments company)

## Enterprise capabilities

### ML models as SQL functions (Enterprise)

Put an ONNX model with its weights in S3, register it through SQL and call it like any function. New models go live without a restart and run on CPU or GPU nodes. Training stays outside.

### GPU acceleration (Enterprise)

Up to 10× faster aggregations, sorts and ML inference on 100M–1B rows (NVIDIA H100 / H200 vs CPU).

### CDC with guarantees (Enterprise)

Change data capture and dual writes with delivery guarantees, running in a cluster. Open source has CDC without guarantees.

## Otterstax vs Trino vs Spice.ai

Why teams pick Otterstax

|  | Otterstax | Trino | Spice.ai |
| --- | --- | --- | --- |
| ML models as SQL functions (ONNX) | ✓ (Enterprise) | — | AI via LLM gateway |

Based on public documentation of each product, September 2026.

## SQL on Kafka, five ways

ksqlDB, Flink SQL, the ClickHouse Kafka engine, the Trino Kafka connector and Otterstax, with code and a stream-to-table JOIN for each.

[SQL on Kafka: 5 ways to query a Kafka topic with SQL →](https://otterstax.com/guides/query-kafka-with-sql)

## Frequently asked questions

### How do ML models run in SQL?

In Enterprise, you put an ONNX model with its weights in S3, register it through SQL and call it as a SQL function. New models go live without a restart and run on Otterstax CPU or GPU nodes. Only inference runs inside Otterstax. Training happens elsewhere, and the model must fit in a node's memory. Any external feature store can read from Otterstax over SQL.

### Can it handle transactional and analytical load together?

Yes. Otterstax sends transactions to row-store databases and analytics to column stores such as ClickHouse or ColumnStore, or runs heavy analytics itself on its columnar engine and GPUs. Query priorities and queues, resource limits, replicas and separate cluster nodes keep analytics from slowing down transactions. It works poorly for transactions that span several databases, analytics on an OLTP database with no replicas, and large JOINs over a slow network.

## Use cases: cross-database joins, analytics without ETL, ML in SQL, database migration

- [One app, many data sources](https://otterstax.com/use-cases/cross-database-joins) — +36.4% daily clients

- [Analytics without ETL](https://otterstax.com/use-cases/analytics-without-etl) — 3 h → real time data latency in dashboards and A/B tests

- [Gradual database migration](https://otterstax.com/use-cases/database-migration) — 1 year instead of the estimated 2

## See Otterstax on your own data sources

In a 30-minute call we'll map your stack and show a working query across your data sources.

[Talk about a pilot](https://otterstax.com/demo) · [Start with open source](https://github.com/otterstax/otterstax/tree/main/examples/quick_start)

---

Source: https://otterstax.com/use-cases/ml-in-sql · Otterstax · info@otterstax.com
