blazer icon indicating copy to clipboard operation
blazer copied to clipboard

Postgres queries with variables broken in 2.6.x

Open kinitawowi opened this issue 4 years ago • 4 comments

After upgrading to 2.6.1, queries on our postgres db with variables now return errors.

The two primary errors observed are:

SELECT * FROM users WHERE id = {row_id}
bind message supplies 0 parameters, but prepared statement "" requires 1 : SELECT * FROM users WHERE id = $1 /*blazer,run_id:7eee8bc0-44db-4439-8661-eb0c86dcaf31*/

And..

SELECT * FROM users WHERE email like concat('%',{value},'%')
could not determine data type of parameter $1 : SELECT * FROM users WHERE email like concat('%',$1,'%') /*blazer,run_id:6a2af629-36fd-443a-a0e3-81191bf81cea*/

Environment:

  • Ruby: 2.7.6
  • Rails: 5.2.7
  • pg: 1.3.5

kinitawowi avatar May 05 '22 14:05 kinitawowi

Hey @kinitawowi, thanks for reporting. I'm not sure how to reproduce the first one. For the second, you can change {value} to {value}::text, but will try to find a way to get it working again without casting (this is related to #392).

ankane avatar May 05 '22 20:05 ankane

Thanks for the info, unfortunately adding the cast changes the second error back to the first one!!

kinitawowi avatar May 06 '22 09:05 kinitawowi

It looks like bind parameters are silently ignored with Active Record < 6.1 when prepared statements are disabled. The commit above should fix it. Thanks again for reporting.

ankane avatar May 06 '22 18:05 ankane

That's fixed for me, thanks...

kinitawowi avatar May 12 '22 10:05 kinitawowi