Re: Tricky SQL problem - retrieve information_schema info and make use of it.

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Paul Linehan <linehanp(at)tcd(dot)ie>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Tricky SQL problem - retrieve information_schema info and make use of it.
Date: 2016-03-22 14:11:16
Message-ID: CAEfWYywit2yAVni71yre_tbpJrtuFEOxUjw1-Pjni=p9yzGj=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Mar 21, 2016 at 3:48 PM, Paul Linehan <linehanp(at)tcd(dot)ie> wrote:

> Hi all,
>
>
> I'll explain the problem and then I'll give you a schema you should
> be able to cut and paste.
>
> I have a system which has different tables for each salesman (please
> don't blame me for this snafu). **Same** table structure for each
> person.
>
> I want to be able to query results for each salesman - but new sales
> personnel are being added and deleted all the time, so a static list
> is not appropriate.
>

OK, we won't blame you. But since the tables are identical, have you
considered inheritance?

Create table allsalespersons... to have a master table with the same
structure as the individual salesperson.

For existing tables, convert them to child tables:
alter table fred inherit allsalespersons;
...

For new tables just create them as inherited to begin with.

Now you can select from "allsalespersons" and get everyone.

Cheers,
Steve

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Paul Linehan 2016-03-22 15:09:53 Re: Tricky SQL problem - retrieve information_schema info and make use of it.
Previous Message Skylar Thompson 2016-03-22 13:53:06 Re: Tricky SQL problem - retrieve information_schema info and make use of it.