On Friday, April 24, 2020 at 3:47:32 PM UTC-7, Dennis O'Connell wrote:
>
> Hi Jeremy
>
> I use Models and i do not have access to DB instance using Rails module.
> Due to this I tried to use *Model.with_sql.*
>
> MemberModel.with_sql('select *
> from members t
> where data @? \'$.alternate_emails[*] ? (@ like_regex
> ".*?.*")\'', query.to_s).all
>
>
> However, I got: *Mismatched number of placeholders (3) and placeholder
> arguments (2) when using placeholder string*
>
> Well, there are 3 question marks indeed but first two of them is not
> parameterized. It belongs to query. Third question mark, however, indeed a
> parameter so query should be passed there.
>
> How can I solve this issue?
>
You could:
1) Use named placeholders (
http://sequel.jeremyevans.net/rdoc/files/doc/querying_rdoc.html#label-Strings+with+Placeholders
)
2) Use a placeholder for the ? operators and substitute the operators using
literal SQL:
MemberModel.with_sql('select *
from members t
where data ? \'$.alternate_emails[*] ? (@ like_regex
".*?.*")\'', Sequel.lit('@?'), Sequel.lit('?') , query.to_s).all
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/3aa4a608-5b9c-4927-9019-e851cb87340b%40googlegroups.com.