Re: Querying the same column and table across schemas

Поиск
Список
Период
Сортировка
От John A. Sullivan III
Тема Re: Querying the same column and table across schemas
Дата
Msg-id 1267821889.15754.49.camel@Family.pacifera.com
обсуждение исходный текст
Ответ на Re: Querying the same column and table across schemas  ("Daniel J. Summers" <daniel.lists@djs-consulting.com>)
Ответы Re: Querying the same column and table across schemas  ("Daniel J. Summers" <daniel.lists@djs-consulting.com>)
Список pgsql-admin
On Fri, 2010-03-05 at 19:59 +0000, Daniel J. Summers wrote:
> 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
>
That sounds quite reasonable.  I'm guessing that a view is superior to
creating a new schema with tables derived from selects from all the
schemas because it would be less overhead and dynamic, i.e., I only
create the view once and it always has the most current data.  Is that
correct?

As we add new schemas, is there an easy way to update the view? That was
not obvious to me looking at the documentation for ALTER VIEW and CREATE
OR REPLACE VIEW seems to be sensitive to ensuring the new view is
identical to the old except for appends.  It would be nice if we could
simply append
UNION SELECT * from user3.sessions
to the view.  Thanks very, very much - John


В списке pgsql-admin по дате отправления:

Предыдущее
От: "Daniel J. Summers"
Дата:
Сообщение: Re: Querying the same column and table across schemas
Следующее
От: Bob Lunney
Дата:
Сообщение: Re: Querying the same column and table across schemas