Personnaly, I don't really like the use of direct bind. You have to build delivery for each mapping with this way, and it becomes quickly hard to maintain.
There is another way that I prefer (in PJ, too) :
Just replace the values of $$$QUERY$$$ and the variable with what you need.
I use "RANK() OVER(ORDER BY ...)" to get an unique ID by row. Of course, you have to adapt it to your SGBD.
Have a nice week-end.