I am using Django 1.7.
I am trying to implement a search functionality. When a search term is entered, I need to search all the tables and all the columns for that term in the DB(I have only 7 tables and probably 40 columns in total and the DB is not very huge). I am using MySQL as the DB.
I can query 1 table, all columns with the following code
query = Q(term__contains=tt) | Q(portal__contains=tt) | ......so on
data = ABC.objects.filter(query)
I tried to use the UNION, write a SQL like
select * from table A where col1 like %s OR col2 like %s .....
UNION
select * from table B where col1 like %s OR col2 like %s .....
When I tried to implement this like below, I got an error "not enough arguments for format string"
cursor = connection.cursor()
cursor.execute("select * from table A where col1 like %s OR col2 like %s
UNION
select * from table B where col1 like %s OR col2 like %s", tt)
So how do I pass the parameters for multiple variables(even though in this case they are the same)? I tried passing it multiple times too.
Thanks.