Limitations & Gotchas

Custom queries has some limitations:

CTEs in raw queries

Sometimes you want to add a CTE to the top of a raw query. Something like WITH t AS (SELECT * FROM other_table). But we use this technique to inject table aliasing as well, which means that when you add a WITH ...., Postgres will complain about an unexpected word WITH.
You can hack around this issue by matching the syntax we use. When we build your query, it looks like this:
table_alias_1 AS (...),
table_alias_2 AS (...),
table_alias_3 AS (...)
${your query here}
So instead of setting your query as WITH alias AS (...) SELECT * FROM ... you should change your raw query to look like:
, your_custom_table_alias AS (...) --- Note the leading , to make the injection work
FROM your_custom_table_alias
Note: This isn't required if using the Knex ORM query builder. This is only needed for running `raw` queries.