Issue with Post.where() causing 500 error
Andrew_Byrne is experiencing an issue with a Postgres query using Post.where() that results in a 500 error. The original query was Post.where('user_id = ? and post_number = ?', params["uid"], params["tid"]).
After examining the logs, Andrew_Byrne found that the issue was with the input value. The query fails when passing multiple values as a string, e.g., Post.where('user_id = ? or topic_id = ?', '1,2', '4, 5').
tgxworld asked for the error message, which was ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "1,2".
tgxworld suggested using Post.where(user_id IN (?) OR topic_id IN (?), [1,2], [4,5]), which helped resolve the issue.
The final solution, as posted by Andrew_Byrne, was to split the string into an array and use the IN operator: posts = Post.where('user_id IN (?) OR topic_id IN (?)', uid, tid).