SQL Segment Extensions
You can generate a Segment Extension using Snowflake SQL queries of Snowflake data. SQL can help you unlock new segment use cases because it offers the flexibility to describe the relationships between data in ways that aren’t achievable through other segmentation features.
The SQL editor is in early access. If you’re interested in participating in the early access, reach out to your customer success manager.
Creating Segment Extensions using SQL
To create a Segment Extension using SQL:
- Go to Segments > Segment Extensions.
- Click Create New Extension and select SQL Editor.
- Add a name for your Segment Extension and input your SQL. See the following sections for requirements and resources.
- Save your Segment Extension.
SQL queries that take longer than 20 minutes to run will time out.
When the extension finishes processing, you can create a segment using your Segment Extension and target this new segment with your campaigns and Canvases.
Writing SQL
Your SQL query should be written using Snowflake syntax. Consult the table reference for a full list of tables and columns available to be queried.
Your SQL must additionally adhere to the following rules:
- Write a single SQL statement. Do not include any semicolons.
- Your SQL must select only one column: the
user_id
column. This means your SQL must contain:
1
SELECT DISTINCT user_id FROM "INSERT TABLE NAME"
Previewing results
Before saving, you can run a preview of your query. Query previews are automatically limited to 100 rows and will timeout after 60 seconds. The user_id
column requirement does not apply when running a preview.
Managing SQL Segment Extensions
On the Segment Extensions page, segments generated using SQL are denoted with next to their name.
Select a SQL Segment Extension to view where the extension is being used, archive the extension, or manually refresh the segment membership.
Refreshing segment membership
To refresh the segment membership of any Segment Extension created using SQL, open the Segment Extension and select Refresh. Currently SQL Segment Extensions do not automatically regenerate.
If you created a segment where you expect users to enter and exit regularly, manually refresh the Segment Extension it uses before targeting that segment in a campaign or Canvas.
Troubleshooting
Your query may fail for any of the following reasons:
- Syntax errors in your SQL query
- SQL does not adhere to the SQL rules
- Processing timeout (after 20 minutes)