> For the complete documentation index, see [llms.txt](https://docs.stacksync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacksync.com/two-way-sync/features/event-triggers/database-query.md).

# 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 %}
