SQL reference
This page documents the R2 SQL syntax based on the currently supported grammar in public beta.
SELECT column_listFROM table_nameWHERE conditions --optional[ORDER BY column_name [DESC | ASC]][LIMIT number]SELECT column_specification [, column_specification, ...]- Column name: column_name
- All columns: *
SELECT * FROM table_nameSELECT user_id FROM table_nameSELECT user_id, timestamp, status FROM table_nameSELECT timestamp, user_id, response_code FROM table_nameSELECT * FROM table_nameSELECT * WHERE condition [AND|OR condition ...]- column_name IS NULL
- column_name IS NOT NULL
- column_name BETWEEN value' AND 'value
- column_name = value
- column_name >= value
- column_name > value
- column_name <= value
- column_name < value
- column_name != value
- column_name LIKE 'value%'
- AND- Logical AND
- OR- Logical OR
- integer - Whole numbers
- float - Decimal numbers
- string - Text values (quoted)
- timestamp - RFC3339 format ('YYYY-DD-MMT-HH:MM:SSZ')
- date - Date32/Data64 expressed as a string ('YYYY-MM-DD')
- boolean - Explicitly valued (true, false)
SELECT * FROM table_name WHERE timestamp BETWEEN '2025-09-24T01:00:00Z' AND '2025-09-25T01:00:00Z'SELECT * FROM table_name WHERE status = 200SELECT * FROM table_name WHERE response_time > 1000SELECT * FROM table_name WHERE user_id IS NOT NULLSELECT * FROM table_name WHERE method = 'GET' AND status >= 200 AND status < 300SELECT * FROM table_name WHERE (status = 404 OR status = 500) AND timestamp > '2024-01-01'--Note: ORDER BY only supports ordering by the partition keyORDER BY partition_key [DESC]- ASC: Ascending order
- DESC: Descending order
- Default: DESC on all columns of the partition key
- Can contain any columns from the partition key
SELECT * FROM table_name WHERE ... ORDER BY paetition_key_ASELECT * FROM table_name WHERE ... ORDER BY partition_key_B DESCSELECT * FROM table_name WHERE ... ORDER BY partitionKey_A ASCLIMIT number- Range: 1 to 10,000
- Type: Integer only
- Default: 500
SELECT * FROM table_name WHERE ... LIMIT 100SELECT *FROM http_requestsWHERE timestamp BETWEEN '2025-09-24T01:00:00Z' AND '2025-09-25T01:00:00Z'LIMIT 100SELECT user_id, timestamp, status, response_timeFROM access_logsWHERE status >= 400 AND response_time > 5000ORDER BY response_time DESCLIMIT 50SELECT timestamp, method, status, user_agentFROM http_requestsWHERE (method = 'POST' OR method = 'PUT')  AND status BETWEEN 200 AND 299  AND user_agent IS NOT NULLORDER BY timestamp DESCLIMIT 1000SELECT user_id, session_id, date_columnFROM user_eventsWHERE session_id IS NOT NULL  AND date_column >= '2024-01-01'ORDER BY timestampLIMIT 500| Type | Description | Example Values | 
|---|---|---|
| integer | Whole numbers | 1,42,-10,0 | 
| float | Decimal numbers | 1.5,3.14,-2.7,0.0 | 
| string | Text values | 'hello','GET','2024-01-01' | 
| boolean | Boolean values | true,false | 
| timestamp | RFC3339 | '2025-09-24T01:00:00Z' | 
| date | 'YYYY-MM-DD' | '2025-09-24' | 
-- Integer comparisonsSELECT * FROM table_name WHERE status = 200SELECT * FROM table_name WHERE response_time > 1000
-- Float comparisonsSELECT * FROM table_name WHERE cpu_usage >= 85.5SELECT * FROM table_name WHERE memory_ratio < 0.8
-- String comparisonsSELECT * FROM table_name WHERE method = 'POST'SELECT * FROM table_name WHERE user_agent != 'bot'SELECT * FROM table_name WHERE country_code = 'US'- Comparison operators: =,!=,<,<=,>,>=,LIKE,BETWEEN,IS NULL,IS NOT NULL
- AND (higher precedence)
- OR (lower precedence)
Use parentheses to override default precedence:
SELECT * FROM table_name WHERE (status = 404 OR status = 500) AND method = 'GET'Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark