Skip to main content

Query Restrictions

Understand the limits, quotas, and permission requirements for running analytics queries in Unkey including row limits and time ranges.
3 min read

This page explains the restrictions, resource limits, and permissions for analytics queries.

Only SELECT Allowed#

Only SELECT queries are permitted. All other SQL statement types return an invalid_analytics_query_type error.

Allowed query patterns:

  • SELECT statements
  • WITH (Common Table Expressions)
  • UNION
  • EXCEPT
  • Subqueries
  • Aggregations
  • Window functions

Not allowed: INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, TRUNCATE, GRANT, REVOKE

Table Access Control#

Queries must reference analytics data through the public, versioned table aliases listed in the endpoint schema reference. Physical ClickHouse table names under default.* are unsupported, including when nested in a CTE or subquery. Attempts to use physical names or other tables such as system.* and information_schema.* return an invalid_analytics_table error.

Function Allow List#

Only explicitly approved functions are allowed. Any function not on this list will be rejected with an invalid_analytics_function error.

Allowed Functions#

Aggregates

count, sum, avg, min, max, any, groupArray, groupUniqArray, uniq, uniqExact, quantile, countIf, sumIf

Date/Time

now, now64, today, toDate, toDateTime, toDateTime64, toStartOfDay, toStartOfWeek, toStartOfMonth, toStartOfYear, toStartOfHour, toStartOfMinute, date_trunc, formatDateTime, fromUnixTimestamp64Milli, toUnixTimestamp64Milli, toIntervalDay, toIntervalWeek, toIntervalMonth, toIntervalYear, toIntervalHour, toIntervalMinute, toIntervalSecond, toIntervalMillisecond, toIntervalMicrosecond, toIntervalNanosecond, toIntervalQuarter

String

lower, upper, substring, concat, length, trim, startsWith, endsWith

JSON
JSONExtractString
Math
round, floor, ceil, abs
Conditional
if, case, coalesce
Type Conversion

toString, toInt32, toInt64, toFloat64

Array

has, hasAny, hasAll, arrayJoin, arrayFilter

Note

If you need a function that's not listed, please contact us at support@unkey.com and we'll review it for inclusion.

Resource Limits#

To ensure fair usage and prevent abuse, queries are subject to resource limits:

Execution Limits#

ResourceLimitPurpose
Max execution time30 secondsPrevent long-running queries
Max execution time (per window)1800 seconds (30 min)Total execution time per hour
Max memory usage1 GBPrevent memory exhaustion
Max result rows10 millionLimit result set size

Query Quotas#

QuotaLimitWindow
Queries per workspace1000Per hour
Note

If you need higher limits for your use case, please contact us at support@unkey.com with details about your specific requirements and expected query volume.

Error Codes#

When limits are exceeded, you'll receive specific error codes:

Error CodeDescriptionSolution
query_execution_timeoutQuery took longer than 30 secondsAdd more filters, reduce time range, use aggregated tables
query_memory_limit_exceededQuery used more than 1GB memoryReduce result set size, add LIMIT clause, use aggregation
query_result_rows_exceededQuery returned more than 10M rowsAdd LIMIT clause, use aggregation, reduce time range
query_quota_exceededExceeded 1000 queries per hourWait for quota to reset, optimize query frequency