Re: Create a row-wise conditional view

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Create a row-wise conditional view
Дата
Msg-id 21687.1122227151@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Create a row-wise conditional view  (Pedro Tarrafeta <ptarra@gmail.com>)
Список pgsql-novice
Pedro Tarrafeta <ptarra@gmail.com> writes:
> I'm trying to create a set of views like this. Let's say I have 2 tables
> with the same structure. One of them is the "master" table (left side) and
> the other one has a different "version" of the fields only for certain rows.

> I want to create a view that would have the same structure as the tables,
> holding all the records from the master table but when there's a record
> matching on the secundary then use those.

Maybe something like

    SELECT * FROM table1
    UNION ALL
    SELECT * FROM table2
      WHERE NOT EXISTS(SELECT 1 FROM table1 where id = table2.id);

(This may have table1 and table2 reversed from what you were thinking.)

This is going to be pretty messy and inefficient, though, so I'd really
counsel rethinking your data design.

            regards, tom lane

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

Предыдущее
От: Sean Davis
Дата:
Сообщение: Re: Utility to Convert MySQL to PostgreSQL
Следующее
От: "Michael Avila"
Дата:
Сообщение: Re: Utility to Convert MySQL to PostgreSQL