If you can change the layout of the database to use partitioning , this is likely to be the way. Then you can just access the "master" table, as if it were a single table, and not several subnets.
You can create a view that joins tables with an additional column corresponding to the table. If all your queries set a value for this extra column, the scheduler should be smart enough to skip scanning all the other tables.
Or you could write a function in PL / pgSQL using EXECUTE to build the appropriate query after retrieving the table name. A function can even return a set so that it can be used in a FROM clause in the same way as a table reference. Or you can simply execute the same query construct in your application logic.
source share