Re: R: aggregate over tables in different schema - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject Re: R: aggregate over tables in different schema
Date
Msg-id 20100111123556.53c2e8e3@dawn.webthatworks.it
Whole thread Raw
In response to R: aggregate over tables in different schema  (Vincenzo Romano <vincenzo.romano@notorand.it>)
List pgsql-general
On Sun, 10 Jan 2010 10:49:48 +0100
Vincenzo Romano <vincenzo.romano@notorand.it> wrote:

> Try using inheritance.

One of the things I didn't mention is: I've to join these tables
with other tables that may or may not (public) belong to the same
schema.

select sum(i.qty) from s1.list_items li
  join public.item i on i.itemid=li.itemid;

Now I'd like to pick up the sum over all list_items tables across
all the schemas.

If I define the summary table as the child of all the sub-tables I'm
going to write dynamic SQL anyway.
So I guess I should define a common ancestor for all the tables
(list_items) in different schema.

create public.list_items (
  itemid int primary key, // trouble
  name varchar(32)
);

create table s1.list_items (
) inherits (public.list_items);

create table s2.list_items (
) inherits (public.list_items);

But I can't see how am I going to write the query.

Furthermore the children should have their own pk and not share them.

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


pgsql-general by date:

Previous
From: Konrad Garus
Date:
Subject: Re: Rows missing from table despite FK constraint
Next
From: Alban Hertroys
Date:
Subject: Re: Get Unix timestamp from SQL timestamp through libpq