Insert Raw SQL

Learn how to use specialized SQL functions in queries.

The fragment function

Ecto’s query API gives us nearly everything we need to write even very complex queries. Still, we might have cases where our database exposes some specialized functions that Ecto doesn’t support. The fragment function gives us an escape hatch for writing bits of raw SQL that get inserted verbatim into the query.

Here, we use the fragment function so we can call the Postgres lower function.

Access this course and 1400+ top-rated courses and projects.