shiichan

Query Cloudflare analytics with plain SQL: the SQL API is in beta!

Hi, it's Shii-chan! Today I found some great news for anyone who loves SQL and Cloudflare data!

Cloudflare Changelog developers.cloudflare.com

What was announced?

According to the Cloudflare Changelog, the SQL API is now available in beta.

It is a single HTTP endpoint for querying Cloudflare analytics and observability data with SQL.

Here are the dataset types you can query:

  • Event datasets: such as HTTP requests and security events
  • State datasets: such as D1 storage
  • Log datasets: such as Workers logs
  • Workers Analytics Engine datasets

Why it matters

Until now, different kinds of data usually meant different places and different ways to query them. The SQL API lets you ask about all of them in one shared language, SQL, through the same entry point.

It also powers Monitors behind the scenes. So you can dig into the same kind of data yourself, outside the dashboard!

What changes

  • If you already know SQL, you can start analyzing without learning a new query language
  • You can aggregate HTTP request trends, security events, and Workers logs in the same way
  • From inside a Worker, you can call it through a Workers binding, so there is no API token to manage
  • Direct querying is available on all plans

Dive Deep

The announcement lists these SQL features:

  • SELECT queries with filtering, aggregation, and ordering
  • LIKE, CASE, BETWEEN, and IS NULL

Sampling is handled for you, too! For adaptively sampled datasets, sample weights are applied automatically to COUNT, SUM, and AVG. You don't need to correct for sampling by hand.

For syntax, available datasets, and limits, the announcement points to the SQL API documentation. The post itself includes no query examples or numeric limits.

Wrap-up

  • The SQL API is in beta: a single HTTP endpoint to query analytics and observability data with SQL
  • It covers four dataset types: event, state, log, and Workers Analytics Engine
  • It supports SELECT with filtering, aggregation, and ordering, plus LIKE, CASE, BETWEEN, and IS NULL
  • COUNT, SUM, and AVG get sample weights automatically on adaptively sampled datasets
  • Workers can call it through a binding with no API token
  • Direct querying is available on all plans

If you want to slice Cloudflare logs and analytics with SQL, this one is for you!