A simple quiz:
Probably many guys know this before,
In my app there is a query in which Im using concat in where condition like this,
v_book_id and v_genre_id are 2 variables in my procedure.
SELECT link_id
FROM link
WHERE concat(book_id,genre_id) = concat(v_book_id,v_genre_id);
Now, I know there is a catch/bug in this, which will occur only twice in your lifetime. Can you tell me what is it?
I found this out yesterday and thought I should make a noise about all others practicing this.
Thanks.
Let’s have a look
as opposed to
There. The second solution is
more correct (as Alnitak also stated in the question’s comments). check out this sample data:
Now add (or concat)
v_book_id = 1andv_genre_id = 12and see how you’ll get funny results with yourconcat()queryNote, some databases (including MySQL) allow operations on tuples, which may be what the clever author of the above really intended to do:
A working example of such a tuple predicate:
Note, some databases will need extra parentheses around the right-hand side tuple :
((1, 2))