postgres
postgres copied to clipboard
👋 Is it possible to provide more information in the error output?
Hi 👋
I'm struggling to debug this query (even after reading the documentation... several times). I know it's highly likely I'm doing something wrong, but I'm wondering if it's possible to add any additional information to the error that is being thrown to help track down the issue? Like outputting the final SQL query with some formatting to highlight which part is failing?
const selectKeys = ['name', ...];
const department = 'food';
const category = undefined;
const field = 'price';
const direction = 'asc';
const productsQuery = sql`
select ${sql(selectKeys)}
from products
where department = ${department}
${category ? sql`and ${category} = any(categories)` : sql``}
${sql`order by ${sql(field)} ${direction}`}
limit ${limit}`;
// PostgresError: syntax error at or near "$2"
Side note: I really like the API of the library, I think you did a great job keeping it as close to writing standard sql while also being super powerful.