I have local data with id's from an external database. I want to then select data from that external database using those id so I do something like:
SELECT * FROM table WHERE id IN (:listofids)
However I've noticed (I'm not sure if it's a DB by DB setting or the type of DB or what) there can be a max number of values allowed in that IN statement. When possible of course I do WHERE id IN (SELECT id FROM ...) but sometimes with external data it's not possible.
My questions:
- What are my options here besides what I am doing in the above?
- Are the limitations of max items set at the DB level, the type of DB, what? Right now I am specifically concerned with an external RedShift DB but I looked at their docs and they don't mention a limit. Our local DB has a limit of 2100 but another one I use is 9999. Also, once the list gets large it can get slow, so i'm looking for a performance boost as well.
- Should I do
in () OR in () OR in(). That doesn't seem too slick. Are all of these options viable? - I've read a bit about possibly using temp tables to do this but without any examples. How would I load data into a temp table to then join into the table I'm wanting to get the data from?