Is there is anyway to pass comparison operator to MySQL query as parameter?
Let’s say I have this query
SELECT * FROM `table1` WHERE `column1` > @p
And instead of > I want to be able to pass < or = depending on condition. I can use string.format(), but I want my query to be parametrized.
And I don’t want to use predefined queries, as long as they differ only in one operator.
MySQL prepared statements only support binding values for variables. Replacing arbitrary part of query string (even for table names) is not supported. In other words, you will have to construct your SQL dynamically on a client.