it's been a while since I have made one of my "Converting MySQL to PostgreSQL" posts.
So, today's problem is as follows:
The original MySQL queries involve where clauses which look a bit like the following:
WHERE id LIKE '%6%'
OR createdtime LIKE '%6%'
OR modifiedtime LIKE '%6%'
OR start_date LIKE '%6%'
OR end_date LIKE '%6%'
OR sc_related_to LIKE '%6%'
OR tracking_unit LIKE '%6%'
OR message LIKE '%6%'
This query is part of a system wide search. In this case, the system is searching for 6, had I asked it to search for something else, like say the word user, instead of %6%, we'd have %user%.
Now, the problem is that, the above data-types are not always strings. Integer fields like id and date/time fields like createdtime are being compared to strings. In MySQL, this seems to be okay, but grumpy PostgreSQL gets grumpy when it sees this query.
I know that for some fields, I can use the to_char function, so, for example, part of the clause in PostgreSQL might look like this:
to_char(id, '999') LIKE '%6%'
Unfortunately, I can't just go throught the queries and add the to_char to each applicable field because of the PHP backend. This is what the PHP code for generating the WHERE clause looks like:
$where .= $tablename.".".$columnname." LIKE '". formatForSqlLike($search_val) ."'";
Note: It's part of a loop, so the above line generates all of the individual comparisons.
So, even if I can get around the type comparison with to_char, I can't implement it because to_char might need a specific 2nd parameter for a different data-type and even if I could use the same parameter for all data-types, some of the data-types would be strings, and passing a string to to_char throws an error.
So, I need a way to either get PHP to determine the column type and use the right to_char(or don't use it at all) accordingly or I need to get PostgreSQL to compare different data-types.
Thanks for all of your help, have a good day!
datecolumn?LIKEworks withdates.PostgreSQL gets grumpy when it sees this query... which speaks well of PosgresSQL.