'how to query many schemas at the same time in postgres

I have a web app with thousands of schemas (one per user). I have seen this post Hibernate and Multi-Tenant Database using Schemas in PostgreSQL where it is mentionned the search_path approach to querrying a particular table in a schema.

I am wondering how to query all the schema at the same time in postgres?

Do I need to implement a python script (for example) to make queries one by one and then gather the results or can I implement that directly in sql to gather all the queries?

For example if I want a table with userid and number_of_posts and i want to query these fields on each user with a separate schema, how would i write that in sql? I dont see how to change the search path in a unique query automatically.

Is there a command in postgres to list all the existing schemas?

Thanks a lot



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source