Bind message supplies 4 parameters, but prepared statement "" requires 6

Just a behaviour we've noticed that might help someone if you come across it.

We have a lot of Shared Queries in our apps and a common thing we do is to filter by date so we might use the same parameter multiple times, e.g.

select id,first, last,
  (
    SELECT COUNT(*) FROM TABLE
    WHERE activity = 'Call' AND ({{ !start_date }} OR date::Date >= {{ start_date }})
  ) calls,
  (
    SELECT COUNT(*) FROM TABLE
    WHERE activity = 'Check-In' AND ({{ !start_date }} OR date::Date >= {{ start_date }})
  ) checkins
  FROM TABLE

We've noticed that if we update this query and add another subselect e.g. (SELECT COUNT(*) FROM TABLE), from our perspective the number of parameters to the Shared Query is still one (start_date).

However, any app that references this Shared Query has stored a copy of the prepared statement where each instance of start_date is treated as it's own parameter so in the above example, {{ start_date }} appears 4 times.

Therefore, if you add another subselect, the expected number of parameters becomes 6 and as a result, all references to the Shared Query in your apps will fail with the "Bind message supplies X parameters, but prepared statement "" requires X". You will need to open every app that references the Shared Query and just click Save & Run and it will update itself.

Just something to be aware of because as the developer, I had assumed as I was using the same parameter, it was a non-breaking change and the app would just work as before... but it doesn't.

I've appended a couple of screenshots for further illustration


1 Like

Thanks for sharing the solution! I was able to reproduce this issue on my side as well