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.

Get hands-on with 1400+ tech skills courses.