Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT sum(honoraria_amount)
- FROM table_1
- table_id
- ----
- 1
- 39
- 42
- SELECT sum(honoraria_amount)
- FROM table_x
- CREATE VIEW union_table (id, name)
- AS ( SELECT honoraria_amount,... FROM foreign_table_1 UNION ALL
- SELECT honoraria_amount, ... FROM foreign_table_2
- ) ;
- create or replace function sum_table(
- tid integer
- ) returns numeric as $$
- declare
- _out numeric;
- begin
- execute 'select sum(honoraria_amount) from table_' || tid::text || ';' into _out;
- return _out;
- end;
- $$ language plpgsql;
- with
- __tables as(
- select unnest(array[1, 39, 42]) as table_id
- )
- select
- table_id,
- sum_table(table_id)
- from
- __tables
Add Comment
Please, Sign In to add comment