Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3Q26-00049O-W1 for pgsql-general@arkaria.postgresql.org; Tue, 03 Apr 2018 17:47:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3Q24-0002cT-Qw for pgsql-general@arkaria.postgresql.org; Tue, 03 Apr 2018 17:47:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3Q24-0002cJ-G7 for pgsql-general@lists.postgresql.org; Tue, 03 Apr 2018 17:47:44 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3Q21-0005Zm-HR for pgsql-general@postgresql.org; Tue, 03 Apr 2018 17:47:43 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 4AE63C1AAFFA for ; Tue, 3 Apr 2018 10:47:40 -0700 (MST) Date: Tue, 3 Apr 2018 10:47:40 -0700 (MST) From: PegoraroF10 To: pgsql-general@postgresql.org Message-ID: <1522777660304-0.post@n3.nabble.com> Subject: single sql, multiple schemas, one result set MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Suppose a DB with dozens of schemas with same structure. DB Schema1 Table1 Table2 Schema2 Table1 Table2 Schema3 Table1 Table2 Then we want to execute a SQL on specific schemas and the result of it could be a UNION ALL. So, how could be a function that runs that SQL on each schema and results just on result set ? Then I would use something like ... select * from SQLFromMultipleShema(Array['Schema1,Schema3'],'select count(*) from Table2'); -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html