Re: Querying a parent table's child schemas

From: "Matthews, James" <jmatthews(at)Railpower(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Querying a parent table's child schemas
Date: 2007-08-30 19:33:06
Message-ID: 067C9A1F6AFEB643895EA4513E116884BB5427@exfp1.Railpowertech.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

In my database there is the public schema (default) with the parent
alarms table. Each 'customer' has their own schema via CREATE SCHEMA,
and then each schema has an alarms table (CREATE TABLE alarm INHERITS
public.alarms). While the tabloid column seems like it should work when
I do the following:

SELECT a.date, a.log_msg, p.relname
FROM alarms a, pg_class p
WHERE a.tableoid = p.oid;

The relname column just lists alarms for every row. I'm looking to find
the schema name, not the table name. Is it a little clearer now?
Regardless thank you for your reply as I believe that it is a step in
the right direction! Any further advice would be appreciated.

Respectfully,

James L. Matthews, III

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Tom Lane
Sent: Thursday, August 30, 2007 12:01 PM
To: Matthews, James
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] Querying a parent table's child schemas

"Matthews, James" <jmatthews(at)Railpower(dot)com> writes:
> I was wondering if there was a way to SELECT from a parent table
> and display the schema associated with a child table's data.

It's not entirely clear to me which meaning of "schema" you have in
mind, but perhaps the tableoid system column would help you? That
lets you determine which child table the row really came from,
and then you can join to the system catalogs to get whatever data
you are actually after.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2007-08-30 19:57:07 Re: Querying a parent table's child schemas
Previous Message Tom Lane 2007-08-30 19:07:43 Re: Could not remove file messages