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

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
