Skip to content

Fix SQL syntax for error rate calculation in Analytics Engine#87

Open
sofiyevsr wants to merge 1 commit into
cloudflare:mainfrom
sofiyevsr:patch-1
Open

Fix SQL syntax for error rate calculation in Analytics Engine#87
sofiyevsr wants to merge 1 commit into
cloudflare:mainfrom
sofiyevsr:patch-1

Conversation

@sofiyevsr

Copy link
Copy Markdown

Summary

Fixes an invalid SQL query example in the Workers Analytics Engine documentation (references/analytics-engine/api.md).

The Workers Analytics Engine SQL API is built on a restricted time-series SQL engine that does not support standard SQL CASE WHEN ... THEN ... END expressions.
Attempting to execute a query using CASE WHEN results in an HTTP 422 error:

  Error: Analytics API error (422): Input was invalid: unsupported expression type: CASE WHEN ...

The supported syntax for conditional logic in Workers Analytics Engine SQL is the if(condition, true_value, false_value) scalar function.

Changes

  • Updated the Error rate example in references/analytics-engine/api.md:
      -- Before
      SUM(CASE WHEN blob3 LIKE '5%' THEN 1 ELSE 0 END) AS errors
    
      -- After
      SUM(if(blob3 LIKE '5%', 1, 0)) AS errors

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant