# Database Query

<figure><img src="/files/oJ45WkQ28KX4nsYWpmVN" alt=""><figcaption></figcaption></figure>

This field will work as a query maker for your database. It should follow the syntax of the database that is being queried.

You can execute any query to the database of your choice, it does not have to be the database that is synced in the sync itself. The query will be executed **as is**, we will not be running any checks to verify if the query is valid. If the query fails or times out, the failure will not stop the execution of other triggers as every trigger will be fired up independently.

The <mark style="color:orange;"><\<record>></mark> placeholder will be replaced by the JSON string containing all the fields of the record. The <mark style="color:orange;"><\<changes>></mark> placeholder will be replaced by the JSON string containing only the updated fields of the record. Properties of the record and changes can be accessed by using a period "." to access the property. This can be nested if the property is a JSON.

For example, a database insert query for PostgreSQL:

```
// Sample <<record>> JSON
{
   "name":"John",
   "address":{
      "street":"123 Main Street",
      "postal_code": 650
   }
}

// PostgreSQL query to insert name and the postal code
INSERT INTO user_table (user_name, postal_code)
VALUES ('<<record>>.name', <<record>>.address.postal_code);
```

{% hint style="info" %}
Notice that the <mark style="color:orange;">`<<record>>.name`</mark>placeholder is enclosed in single quotes as the column is of type string whereas <mark style="color:orange;">`<<record>>.address.postal_code`</mark> is not enclosed in single quotes as the column is of type int.

The query should follow the syntax of the database.
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://docs.stacksync.com/two-way-sync/features/event-triggers/database-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
