postgres icon indicating copy to clipboard operation
postgres copied to clipboard

Dynamic queries not working properly

Open kronos-999 opened this issue 2 years ago • 1 comments

Hello, I am trying to implement query fragments as described in your dynamic query section. I have the following:

const results = await sql`
    SELECT
      *
    FROM
      schema.table
    WHERE
      shorts_availabilities && ARRAY[${body.timespan}]::date[]
    ${body.areas !== 0 ? sql`AND areas && ARRAY[${body.area}]::INTEGER[]` : sql``}
    `

I get a syntax error at "AND"

kronos-999 avatar Nov 20 '23 12:11 kronos-999

I think you might need to change && to AND

MikeBellika avatar Nov 20 '23 13:11 MikeBellika