> For the complete documentation index, see [llms.txt](https://docs.aporia.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aporia.com/api-reference/custom-segment-syntax.md).

# Custom Segment Syntax

In Aporia, [custom segments](/core-concepts/tracking-data-segments.md) are defined using SQL-based syntax.

The definition is written as a condition that will be passed to a WHERE clause. The condition should be based only on fields within your model version schema.

The following SQL operators are supported:

```sql
>, <, <=, >=, !=, &, |, =, is, not, or, and
```

{% hint style="warning" %}
Categorical fields are ingested as strings.\
If your segment includes a comparison of a categorical field and a constant value, remember to quote the constant value.
{% endhint %}

<figure><img src="/files/vAOJzWQ8aAssJ5wPUEY9" alt=""><figcaption><p>Custom Segments Creation</p></figcaption></figure>

## Examples

1. Assume we have a numeric field "age" and a boolean field "is\_customer" in our schema, we can create a segment based on these fields as follows:

```sql
--Segment of customers above age 23
age > 23 and is_customer = True
```

2. Assume we have a categorical field "partner\_type" and categorical field "deal\_step" in our schema, we can create a segment based on these fields as follows:

```sql
--Segment of all 'Gold' partners with missing deal stage
partner_type = 'Gold' and deal_stage is null
```

3. Assume we have a categorical field "region\_code" in our schema, we can create a segment based on this field as follows:

```sql
--Segment of all data with region_code different than '123'
region_code != '123'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aporia.com/api-reference/custom-segment-syntax.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
