# 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: 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.locoia.com/data-and-dashboards/dashboards-and-insights/writing-sql-queries.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.
