---
title: "Custom Queries · WitCloud Docs"
description: "The Custom Queries module allows you to create, run, and automate your own SQL queries within the data stored in your data warehouse — both data collected by…"
canonical_url: "https://witcloud.ai/docs/integrations/custom-queries"
meta:
  "og:description": "The Custom Queries module allows you to create, run, and automate your own SQL queries within the data stored in your data warehouse — both data collected by…"
  "og:image": "https://witcloud.ai/og-default.png"
  "og:title": "Custom Queries · WitCloud Docs"
---

> Index of every page on this site: [llms.txt](https://witcloud.ai/llms.txt)

# Custom Queries integration

Updated 1 Nov 2026

## Introduction

The **Custom Queries** module allows you to create, run, and automate your own SQL queries within the data stored in your data warehouse — both data collected by WitCloud and data from external sources. This enables you to create custom views, reports, and datasets without modifying the main dataset structure.

## Configuration guide

Follow the steps below to create the **Custom Queries** module.

### Module configuration

Go to **Integrations** in the menu and click **Add integration**.

![Integrations list with the Add integration button](https://api.witcloud.ai/api/docs/assets/3a20e9e7d1f0be8684240e41f29ca67c.png)

From the list of available integrations, select **Custom Queries**.

![Integration catalog with Custom Queries selected](https://api.witcloud.ai/api/docs/assets/a385779fbae672da87b4d0130b76a05e.png)

Enter the **Custom Query name**, e.g., `"Example Custom Query"`.

![Custom Query name field filled in with the example name Example Custom Query](https://api.witcloud.ai/api/docs/assets/f374b76f3fe7421fc5e901cb213d5914.png)

Enter the SQL query in the **Query content** field. You can use the full BigQuery syntax and the `{{RUN_DATE}}` variable, which will automatically be replaced with the process execution date.

The `{{RUN_DATE}}` variable follows the `YYYYMMDD` format and corresponds to the scheduled task execution date or the manual run date.

![Query content field filled in with an example SQL query using the RUN\_DATE variable](https://api.witcloud.ai/api/docs/assets/40d5b6479ff5756da5267ceec38a314c.png)

### Saving results

To save the query results in BigQuery, enable the **Save Query results** switch. Without it, the query is only run and nothing is written.

The **Table settings** section appears. In **Destination table**, enter the name of the table the results are written to. The default is `results_{id}`: `{id}` becomes the Custom Query's own id, so every query gets a table of its own. The name may contain only letters, digits and `_`, is written in lowercase, and the table is always in your project's dataset - the text above the field shows where the results go.

![Save Query results switched on, with the Table settings section - Destination table with its default results\_ and where the results are written, Write disposition, Clustering and Partitioned](https://api.witcloud.ai/api/docs/assets/a8aebe8b9d99db93bfc7deb9dbfff6b9.png)

Two Custom Queries of a project cannot write to the same table.

**Write disposition** – the method of writing data:

- **Overwrite if table/partition exists** – replaces the table, or with partitioning by **Ingestion time** only the partition of the run's date.
- **Append to table/partition** – appends the results to the table.
- **Write only if table/partition is empty** – writes only if the table (or the run date's partition) is empty.

![Write disposition drop-down open with Overwrite if table/partition exists, Append to table/partition and Write only if table/partition is empty](https://api.witcloud.ai/api/docs/assets/b7940ed6fd9cd5a8b677f12d3619e3d7.png)

With **Append to table/partition**, or **Overwrite if table/partition exists** on a table partitioned by **Ingestion time**, columns you add to the query are added to the table automatically.

### Clustering

**Clustering** orders the stored data by up to 4 of the query's result columns. Enter the column names separated by commas, in the order you filter by most, e.g. `channel, country`. Leave it empty for no clustering.

![Write disposition set to Overwrite if table/partition exists and Clustering filled in with channel, country](https://api.witcloud.ai/api/docs/assets/8b4b76a194bff5de9a44b7ae5762bacc.png)

The columns must be among the query's result columns and of a type BigQuery can cluster on, and cannot repeat. When you change the clustering of a query whose table already exists, the table is changed with the next run.

### Data partitioning

If you want the results to be saved in a partitioned table, enable the **Partitioned** option. The **Partitioning settings** section appears:

- **Partitioning by**:
  - **Ingestion time** – each run writes the partition of its own date.
  - **Custom field** – partitions by a column of the query's results. Enter its name in the **Custom field** box; the column must be `DATE`, `TIMESTAMP` or `DATETIME`.
- **Partition type** – **Day**, **Month** or **Year**, and **Hour** with a **Custom field** of type `TIMESTAMP` or `DATETIME`. The default is **Day**.
- **Partition expiration (days)** – partitions older than this many days are deleted. Leave it empty to keep them forever.
- **Require partition filter** – every query of this table must filter on the partitioning column ( `_PARTITIONTIME` with **Ingestion time**), or BigQuery refuses it. That includes All in One, data sources and other queries that read this table, so switch it on only when they all filter on it.

![Partitioning settings - partitioning by the custom field date, Partition type Day, Partition expiration 730 days and Require partition filter switched on with its warning](https://api.witcloud.ai/api/docs/assets/91cabbcd26a60c4a4b5fedaf5c56d7ca.png)

This allows you to easily manage large datasets and speed up processing in BigQuery.

### Query testing

Before saving the configuration, click **Test Query**. This runs a dry run of the query, which costs nothing and writes no data. `{{RUN_DATE}}` is replaced with yesterday's date. The test also checks the **Table settings** against the columns the query returns.

![Test Query and Create buttons below the form](https://api.witcloud.ai/api/docs/assets/15b53777da9b660cceff3b8a313ccf24.png)

If the query is correct, the **Query success** window shows how much data one run processes (**Processes** ... per run), the **Test date**, the **Statement type**, the tables it **Reads** and its **Result columns**.

![Query success window with example dry run results - data processed per run, test date, statement type, the table it reads and the result columns](https://api.witcloud.ai/api/docs/assets/64a4fae718f353c03d82f525031419ba.png)

Otherwise the **Query error** window shows the error from BigQuery, or under **Table settings** what in the table settings does not fit the query (see [Troubleshooting](#troubleshooting)).

![Query error window whose Table settings list says the example clustering column region is not among the query's columns](https://api.witcloud.ai/api/docs/assets/8d563f6eed7ee7464bd5d550527ef706.png)

Click **Create** to save the module. **Create** runs the same test first: if it finds a problem, nothing is saved and the **Not saved: fix the query** window shows what to fix.

**Done!** The **Custom Query** module has appeared on the **Integrations** list and is now ready to use.

Remember that the table will appear only after the module is run in the Workflow!

To change a Custom Query later, open it from the **Integrations** list, change the settings and click **Save**. **Save** runs the test too.

### Execution and scheduling

To run the module and set up its schedule, you need to configure a **Workflow**. You can read more about it [here](https://witcloud.ai/docs/workflow).

## Troubleshooting

The test and **Create**/**Save** can report these problems with the table settings:

- **The table name cannot contain a dot: results always go to the project dataset.** – enter the table name without a dataset.
- **The table name may contain only letters, digits and \_.** / **The only placeholder a table name takes is {id}.** – remove the other characters from **Destination table**.
- **Clustering takes at most 4 columns.** / **Clustering columns cannot repeat.** – shorten the **Clustering** list.
- `Clustering column "…" is not among the query's columns` / `Partitioning column "…" is not among the query's columns` – the column is missing from the query's results; check its name in **Result columns**.
- `Partitioning column "…" is STRING; it must be DATE, TIMESTAMP, DATETIME` – partition by a date or time column, or convert the column in the query.
- `Query job "…" already writes to …; choose another destinationTable` – another Custom Query of the project writes to this table; choose another **Destination table**.

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://witcloud.ai/#website","@type":"WebSite","description":"WitCloud is a marketing and e-commerce analytics platform: connect your data, ask AI and track KPIs in one place.","inLanguage":"en-US","name":"WitCloud","url":"https://witcloud.ai/","publisher":{"@id":"https://witcloud.ai/#identity"}},{"@id":"https://witcloud.ai/docs/integrations/custom-queries#webpage","@type":"WebPage","dateModified":"2026-11-01T08:57:53.217Z","description":"The Custom Queries module allows you to create, run, and automate your own SQL queries within the data stored in your data warehouse — both data collected by…","name":"Custom Queries · WitCloud Docs","url":"https://witcloud.ai/docs/integrations/custom-queries","breadcrumb":{"@id":"https://witcloud.ai/docs/integrations/custom-queries#breadcrumb"},"isPartOf":{"@id":"https://witcloud.ai/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://witcloud.ai/docs/integrations/custom-queries"]}],"primaryImageOfPage":{"@id":"https://witcloud.ai/#logo"}},{"@id":"https://witcloud.ai/#identity","@type":"Organization","name":"WitCloud","url":"https://witcloud.ai","logo":{"@id":"https://witcloud.ai/#logo"},"sameAs":[]},{"@id":"https://witcloud.ai/docs/integrations/custom-queries#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Integrations","item":"https://witcloud.ai/docs/integrations","position":1},{"@type":"ListItem","name":"Custom Queries","item":"https://witcloud.ai/docs/integrations/custom-queries","position":2}]},{"@id":"https://witcloud.ai/docs/integrations/custom-queries#article","dateModified":"2026-11-01T08:57:53.217Z","description":"The Custom Queries module allows you to create, run, and automate your own SQL queries within the data stored in your data warehouse — both data collected by WitCloud and data from external sources.","headline":"Custom Queries","inLanguage":"en-US","thumbnailUrl":"https://witcloud.ai/og-default.png","@type":["Article","TechArticle"],"author":{"@id":"https://witcloud.ai/docs/integrations/custom-queries#/schema/person/1"},"image":{"@id":"https://witcloud.ai/docs/integrations/custom-queries#/schema/image/1"},"isPartOf":{"@id":"https://witcloud.ai/docs/integrations/custom-queries#webpage"},"mainEntityOfPage":{"@id":"https://witcloud.ai/docs/integrations/custom-queries#webpage"},"publisher":{"@id":"https://witcloud.ai/#identity"}},{"@id":"https://witcloud.ai/docs/integrations/custom-queries#/schema/person/1","@type":"Person","name":"WitCloud"},{"@id":"https://witcloud.ai/#logo","@type":"ImageObject","caption":"WitCloud","contentUrl":"https://witcloud.ai/logo.svg","inLanguage":"en-US","url":"https://witcloud.ai/logo.svg"},{"@id":"https://witcloud.ai/docs/integrations/custom-queries#/schema/image/1","@type":"ImageObject","contentUrl":"https://witcloud.ai/og-default.png","inLanguage":"en-US","url":"https://witcloud.ai/og-default.png"}]}
```

## Sitemap

See the full [sitemap](https://witcloud.ai/sitemap.md) for all pages.
