pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedsingle sql, multiple schemas, one result set
3+ messages / 3 participants
[nested] [flat]
* single sql, multiple schemas, one result set
@ 2018-04-03 17:47 PegoraroF10 <marcos@f10.com.br>
2018-04-03 18:05 ` Re: single sql, multiple schemas, one result set Guyren Howe <guyren@gmail.com>
2018-04-03 18:12 ` Re: single sql, multiple schemas, one result set Rob Sargent <robjsargent@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: PegoraroF10 @ 2018-04-03 17:47 UTC (permalink / raw)
To: pgsql-general
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: single sql, multiple schemas, one result set
2018-04-03 17:47 single sql, multiple schemas, one result set PegoraroF10 <marcos@f10.com.br>
@ 2018-04-03 18:05 ` Guyren Howe <guyren@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Guyren Howe @ 2018-04-03 18:05 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; +Cc: pgsql-general
Make a view that joins all the things, with a column providing the name of the schema that they came from.
> On Apr 3, 2018, at 10:47 , PegoraroF10 <marcos@f10.com.br> wrote:
>
> 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
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: single sql, multiple schemas, one result set
2018-04-03 17:47 single sql, multiple schemas, one result set PegoraroF10 <marcos@f10.com.br>
@ 2018-04-03 18:12 ` Rob Sargent <robjsargent@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Rob Sargent @ 2018-04-03 18:12 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 04/03/2018 11:47 AM, PegoraroF10 wrote:
> 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
>
Should work if you add a tag to every table referenced in the sql sent in:
select * from SQLFromMultipleShema(Array['Schema1,Schema3'],'select count(*)
from SCHEMA_NAME.Table2')
Then, in a loop over the schema name array replacing the SCHEMA_NAME as you build up a union of your injected sql.
Or perhaps loop over the schame name array reseting search_path as you build up a temp table of the result from the sql passed in as an argument.
Pretty sure you're going to end up need "dynamic sql";
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-04-03 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 17:47 single sql, multiple schemas, one result set PegoraroF10 <marcos@f10.com.br>
2018-04-03 18:05 ` Guyren Howe <guyren@gmail.com>
2018-04-03 18:12 ` Rob Sargent <robjsargent@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox