> For the complete documentation index, see [llms.txt](https://docs.locoia.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.locoia.com/data-and-dashboards/dashboards-and-insights/writing-sql-queries.md).

# Writing SQL Queries

## SQL-Dialect

The SQL dialect used is **Postgres**. You can find a detailed description of how to create queries here: [https://www.postgresql.org/docs/current/queries.html](<https://www.postgresql.org/docs/current/queries.html >).

{% hint style="warning" %}
In PostgreSQL **unquoted names are case-insensitive**. This means that `SELECT * FROM mytable` and `SELECT * FROM myTable` are equivalent and both tables are interpreted as `mytable`.

However, **quoted names are case-sensitive**. So in case there is any casing in either your table or column names you should use quotes, e.g. `SELECT * FROM "myTable"`.
{% endhint %}

## Available Functions

Following the the available functions and autocomplete terms that you can use inside your SQL queries

* \#>
* \#>>
* $end\_date
* $start\_date
* \*
* ->
* ->>
* ::
* <
* \>
* AND
* AS
* ASC
* AVG
* BTRIM
* CASE
* CAST
* COALESCE
* CONCAT
* CONCAT\_WS
* COUNT
* CURRENT\_DATE
* DATE
* DATE\_PART
* DATETRUNC
* DESC
* DISTINCT
* ELSE
* END
* FALSE
* FLOAT
* FROM
* FULL OUTER JOIN
* GENERATESERIES
* GROUP BY
* IFNULL
* ILIKE
* INITCAP
* INNER JOIN
* INT
* INTERVAL
* JSON
* LEFT OUTER JOIN
* LEFT
* LENGTH
* LIKE
* LIMIT
* LOWER
* LPAD
* LTRIM
* NOT ILIKE
* NOT LIKE
* NULL
* ON
* OR
* ORDER BY
* REGEXP\_MATCHES
* REGEXP\_REPLACE
* REPEAT
* REPLACE
* REVERSE
* RIGHT OUTER JOIN
* RIGHT
* RPAD
* RTRIM
* SELECT
* SPLIT\_PART
* SUBSTRING
* SUM
* TEXT
* THEN
* TIMESTAMP
* TRUE
* UNION ALL
* UNION
* UPPER
* WHEN
* WHERE


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.locoia.com/data-and-dashboards/dashboards-and-insights/writing-sql-queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
