I have a set of sql – queries:
List<String> queries = ...
queries[0] = "select id from person where ...";
...
queries[8756] = "select id from person where ...";
Each query selects rows from the same table ‘person’. The only difference is the where-clause.
Table ‘person’ looks like this:
id | name | ... many other columns
How can i determine which queries will contain a certain person in it’s result set?
For example:
List<Integer> matchingQueries = magicMethod(queries, [23,45]);
The list obtained by ‘magicMethod’ filters all sql queries present in the list ‘queries’ (defined above) and returns only those that contain either the person with id 23 OR a person with id 45.
Why i need it:
I am dealing with an application that contains products and categories where the categories are sql queries that define which products belong to them (queries stored in a table also).
Now i have a requirement where an admin has to see all categories an item belongs to immediately after the item was created. Btw, over 8.000 categories defined (so far, more to come).
language and db: java && postgreSQL
Thanks,
I can think of 2 ways. First way is to create a value object
Querywhich contains two properties: aLong idquery ID and aList<Person>results. Another way is to include the query ID in the results. E.g.or
so that you can re-obtain it by
That said, this is all with all a bit a smell (DRY). I’d recommend to rethink the whole approach. Feel free to ask it as a new question, “I have functional requirement XYZ, I have approached it as follows. Is it right?”.