ankane / blazer

Business intelligence made simple
MIT License
4.56k stars 474 forks source link

Postgres queries with variables broken in 2.6.x #397

Closed kinitawowi closed 2 years ago

kinitawowi commented 2 years ago

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:

ankane commented 2 years ago

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).

kinitawowi commented 2 years ago

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

ankane commented 2 years ago

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.

kinitawowi commented 2 years ago

That's fixed for me, thanks...