- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9.8k
 
Adding R2 SQL docs #25338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            jonesphillip
  merged 33 commits into
  cloudflare:production
from
Marcinthecloud:mselwan-pipeline
  
      
      
   
  Sep 25, 2025 
      
    
  
     Merged
                    Adding R2 SQL docs #25338
Changes from 12 commits
      Commits
    
    
            Show all changes
          
          
            33 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      cb03a30
              
                initial docs
              
              
                Marcinthecloud 1cbebac
              
                fixed link in index
              
              
                Marcinthecloud dd0e8d5
              
                fix indents in index, add query-data
              
              
                Marcinthecloud 87e5a32
              
                Improved all docs, added index.mdx in platform
              
              
                Marcinthecloud b8abf91
              
                removed redundant command
              
              
                Marcinthecloud 1f9632f
              
                A ton of changes and improvements
              
              
                Marcinthecloud 9512bde
              
                Update get-started.mdx
              
              
                Marcinthecloud 579cbf2
              
                Update end-to-end-pipeline.mdx
              
              
                Marcinthecloud 3b1acc7
              
                added dash steps/tabs, moved out of r2, reformatted most of the R2 SQ…
              
              
                Marcinthecloud 5a27768
              
                added new R2 SQL token env variable
              
              
                Marcinthecloud dde1d62
              
                adding wrangler commands
              
              
                Marcinthecloud 74b405c
              
                Update .gitignore
              
              
                Marcinthecloud d08b951
              
                PCX Review
              
              
                Oxyjun 741c9ed
              
                Update src/content/docs/r2-sql/reference/limitations-best-practices.mdx
              
              
                Marcinthecloud 79680f6
              
                adding improvements from the latest round of reviews
              
              
                Marcinthecloud 39c0e8c
              
                Merge branch 'mselwan-pipeline' of https://github.com/Marcinthecloud/…
              
              
                Marcinthecloud be11616
              
                fixed min permissions needed
              
              
                Marcinthecloud 205b4a4
              
                more improvements from reviews
              
              
                Marcinthecloud f199743
              
                Merge branch 'mselwan-pipeline' of https://github.com/Marcinthecloud/…
              
              
                Marcinthecloud f5d33f5
              
                Update src/content/docs/r2-sql/platform/pricing.mdx
              
              
                Marcinthecloud 5004c64
              
                Update src/content/docs/r2-sql/reference/limitations-best-practices.mdx
              
              
                Marcinthecloud b7693e4
              
                Update src/content/docs/r2-sql/reference/sql-reference.mdx
              
              
                Marcinthecloud ca29d7d
              
                Adding improvements from Nikita's review
              
              
                Marcinthecloud b15a5a0
              
                Merge branch 'mselwan-pipeline' of https://github.com/Marcinthecloud/…
              
              
                Marcinthecloud 8318059
              
                changed the getting started to match Pipelines for consistency
              
              
                Marcinthecloud 5a67919
              
                Small formatting + other changes
              
              
                jonesphillip 8f7f5e9
              
                fixed typo and added the changelog
              
              
                Marcinthecloud 803fcd1
              
                Add redirect for troubleshooting guide
              
              
                jonesphillip c88356a
              
                Chagnes to changelog
              
              
                jonesphillip 501babb
              
                Fixes pipeline, broken links
              
              
                jonesphillip 6f1c557
              
                adding our official r2-sql icon
              
              
                Marcinthecloud 83ab7c9
              
                addressing Yevgen's feedback
              
              
                Marcinthecloud 2b18964
              
                fix typo in getting started for r2 sql
              
              
                jonesphillip File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -29,4 +29,4 @@ pnpm-debug.log* | |
| /assets/secrets | ||
| /worker/functions/ | ||
| 
     | 
||
| .idea | ||
| .idea | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,337 @@ | ||||||
| --- | ||||||
| pcx_content_type: get-started | ||||||
| title: Getting started | ||||||
| head: [] | ||||||
| sidebar: | ||||||
| order: 2 | ||||||
| description: Learn how to get up and running with R2 SQL using R2 Data Catalog and Pipelines | ||||||
| --- | ||||||
| import { | ||||||
| Render, | ||||||
| Steps, | ||||||
| Tabs, | ||||||
| TabItem, | ||||||
| DashButton, | ||||||
| LinkCard, | ||||||
| } from "~/components"; | ||||||
| 
     | 
||||||
| ## Overview | ||||||
| 
     | 
||||||
| This guide will instruct you through: | ||||||
| 
     | 
||||||
| - Creating an [R2 bucket](/r2/buckets/) and enabling its [data catalog](/r2/data-catalog/). | ||||||
| - Using Wrangler to create a Pipeline Stream, Sink, and the SQL that reads from the stream and writes it to the sink | ||||||
| - Sending some data to the stream via the HTTP Streams endpoint | ||||||
| - Querying the data using R2 SQL | ||||||
| 
     | 
||||||
| ## Prerequisites | ||||||
| 
     | 
||||||
| 1. Sign up for a [Cloudflare account](https://dash.cloudflare.com/sign-up). | ||||||
| 2. Install [Node.js](https://nodejs.org/en/). | ||||||
| 3. Install [Wrangler](/workers/wranger/install-and-update) | ||||||
| 
     | 
||||||
| :::note[Node.js version manager] | ||||||
| Use a Node version manager like [Volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm) to avoid permission issues and change Node.js versions. Wrangler requires a Node version of 16.17.0 or later. | ||||||
| ::: | ||||||
| 
     | 
||||||
| ## 1. Set up authentication | ||||||
| 
     | 
||||||
| You'll need API tokens to interact with Cloudflare services. | ||||||
| 
     | 
||||||
| <Steps> | ||||||
| 1. In the Cloudflare dashboard, go to the **R2 object storage** page. | ||||||
| <DashButton url="/?to=/:account/r2/overview" /> | ||||||
| 
     | 
||||||
| 2. Select **Manage API tokens**. | ||||||
| 
     | 
||||||
| 3. Select **Create API token**. | ||||||
                
      
                  Marcinthecloud marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||
| 
     | 
||||||
| 4. Select the **R2 Token** text to edit your API token name. | ||||||
| 
     | 
||||||
| 5. Under **Permissions**, choose the **Admin Read & Write** permission. | ||||||
| 
     | 
||||||
| 6. Select **Create API Token**. | ||||||
                
      
                  Marcinthecloud marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||
| 
     | 
||||||
| 7. Note the **Token value**. | ||||||
| 
     | 
||||||
| </Steps> | ||||||
| 
     | 
||||||
| Export your new token as an environment variable: | ||||||
| 
     | 
||||||
| ```bash | ||||||
| export WRANGLER_R2_SQL_AUTH_TOKEN= #paste your token here | ||||||
| ``` | ||||||
| 
     | 
||||||
| If this is your first time using Wrangler, make sure to login. | ||||||
| ```bash | ||||||
| npx wrangler login | ||||||
| ``` | ||||||
| 
     | 
||||||
| ## 2. Create an R2 bucket and enable R2 Data Catalog | ||||||
                
      
                  Marcinthecloud marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||
| 
     | 
||||||
| <Tabs syncKey='CLIvDash'> | ||||||
| <TabItem label='Wrangler CLI'> | ||||||
| 
     | 
||||||
| Create an R2 bucket: | ||||||
| 
     | 
||||||
| ```bash | ||||||
| npx wrangler r2 bucket create r2-sql-demo | ||||||
| ``` | ||||||
| 
     | 
||||||
| </TabItem> | ||||||
| <TabItem label='Dashboard'> | ||||||
| 
     | 
||||||
| <Steps> | ||||||
| 1. In the Cloudflare dashboard, go to the **R2 object storage** page. | ||||||
| <DashButton url="/?to=/:account/r2/overview" /> | ||||||
| 
     | 
||||||
| 2. Select **Create bucket**. | ||||||
| 
     | 
||||||
| 3. Enter the bucket name: r2-sql-demo | ||||||
| 
     | 
||||||
| 4. Select **Create bucket**. | ||||||
| </Steps> | ||||||
| </TabItem> | ||||||
| </Tabs> | ||||||
| 
     | 
||||||
| ## 2. Enable R2 Data Catalog | ||||||
                
      
                  Marcinthecloud marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||||||
| 
     | 
||||||
| <Tabs syncKey='CLIvDash'> | ||||||
| <TabItem label='Wrangler CLI'> | ||||||
| 
     | 
||||||
| Enable the catalog on your R2 bucket: | ||||||
| 
     | 
||||||
| ```bash | ||||||
| npx wrangler r2 bucket catalog enable r2-sql-demo | ||||||
| ``` | ||||||
| 
     | 
||||||
| When you run this command, take note of the "Warehouse". You will need these later. | ||||||
| 
     | 
||||||
| </TabItem> | ||||||
| <TabItem label='Dashboard'> | ||||||
| 
     | 
||||||
| <Steps> | ||||||
| 1. In the Cloudflare dashboard, go to the **R2 object storage** page. | ||||||
| <DashButton url="/?to=/:account/r2/overview" /> | ||||||
| 
     | 
||||||
| 2. Select the bucket: r2-sql-demo. | ||||||
| 
     | 
||||||
| 3. Switch to the **Settings** tab, scroll down to **R2 Data Catalog**, and select **Enable**. | ||||||
| 
     | 
||||||
| 4. Once enabled, note the **Catalog URI** and **Warehouse name**. | ||||||
| </Steps> | ||||||
| </TabItem> | ||||||
| </Tabs> | ||||||
| 
     | 
||||||
| 
     | 
||||||
| :::note | ||||||
| Copy the warehouse (ACCOUNTID_BUCKETNAME) and paste it in the `export` below. We'll use it later in the tutorial. | ||||||
| ::: | ||||||
| 
     | 
||||||
| ```bash | ||||||
| export $WAREHOUSE= #Paste your warehouse here | ||||||
| ``` | ||||||
| 
     | 
||||||
| ## 3. Create the data Pipeline | ||||||
| 
     | 
||||||
| <Tabs syncKey='CLIvDash'> | ||||||
| <TabItem label='Wrangler CLI'> | ||||||
| ### 1. Create the Pipeline Stream | ||||||
| 
     | 
||||||
| First, create a schema file called `demo_schema.json` with the following `json` schema: | ||||||
| ```json | ||||||
| { | ||||||
| "fields": [ | ||||||
| {"name": "user_id", "type": "int64", "required": true}, | ||||||
| {"name": "payload", "type": "string", "required": false}, | ||||||
| {"name": "numbers", "type": "int32", "required": false} | ||||||
| ] | ||||||
| } | ||||||
| ``` | ||||||
| Next, crete the stream we'll use to ingest events to: | ||||||
                
       | 
||||||
| Next, crete the stream we'll use to ingest events to: | |
| Next, create the stream we'll use to ingest events to: | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.