# How to: Execute SQL

This guide demonstrates how to create an expression that executes an SQL query to a PostgreSQL database using the ODBC driver. The ODBC driver for PostgreSQL must be installed on the target machine before starting.&#x20;

{% hint style="warning" %}
Please note that calling the *executeScalar* function will immediately put the script module into demo mode if it is not licensed
{% endhint %}

Open Monokot Server Administrator and double-click *Scripts* on the *Server Explorer* pane. Click *New Expression*, set the name *PgDateTime* for the expression that appears and set the *STRING* type for the return data. Insert the following code into the expression code editor:

```javascript
var connectionString = 'DRIVER={PostgreSQL UNICODE};Server=localhost;Port=5432;UID=postgres;PWD=qwerty;';
return MosOdbc.executeScalar(connectionString, 'SELECT now();');
```

Note that in the server connection line you need to specify your server credentials (*Server, Port, UID, PWD*). Press *Ctrl + Enter* to apply the change in the code editor.

Go to the *Triggers* tab and click *Add Periodic*. In order for the changes to take effect on the server, click the Sync button. Thus, the expression will return the current date and time received from PostgreSQL every 500 ms.

You can find the full set of *MosOdbc* functions and their descriptions [<mark style="color:blue;">here</mark>](/scripts/api/mosodbc.md).


---

# 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.monokot.io/scripts/programming-examples/how-to-execute-sql.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.
