Re: Querying the same column and table across schemas

From: "Daniel J(dot) Summers" <daniel(dot)lists(at)djs-consulting(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Querying the same column and table across schemas
Date: 2010-03-05 19:59:00
Message-ID: 4B916284.3040401@djs-consulting.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 03/05/2010 07:44 PM, John A. Sullivan III wrote:
> I'm trying to avoid making a thousand call like
>
> select user1.session_id from user1.sessions;
>
> when I could do it in a single query especially since the database is
> remote and secured with SSL.
>
CREATE VIEW all_sessions AS
SELECT user1.session_id, 1 as user_number
FROM user1.sessions
UNION
SELECT user2.session_id, 2 AS user_number
FROM user2.sessions
UNION
...more schemas...

Then, "SELECT * FROM all_sessions" would show you each session ID (and,
with the user_number field, what user - you could use a string literal
there too). Of course, the user creating and running this would need
SELECT privileges on each schema's "sessions" table.

Daniel

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message John A. Sullivan III 2010-03-05 20:44:49 Re: Querying the same column and table across schemas
Previous Message John A. Sullivan III 2010-03-05 19:44:43 Querying the same column and table across schemas