Re: Implementation of a updateable, "temporal" view on data

Поиск
Список
Период
Сортировка
От Richard Broersma Jr
Тема Re: Implementation of a updateable, "temporal" view on data
Дата
Msg-id 905375.5251.qm@web31806.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Implementation of a updateable, "temporal" view on data  (Hans-Peter Oeri <hp@oeri.ch>)
Ответы Re: Implementation of a updateable, "temporal" view on data
Список pgsql-novice
--- Hans-Peter Oeri <hp@oeri.ch> wrote:
> I tried to implement this using pgsql rules on the view - but I seem
> unable to restrict step a to only THE old row:
> UPDATE table SET stop=now() WHERE table.id=old.id AND table.start=old.start
> is "translated" to:
> ... WHERE table.id=table.id AND table.start=table.start
> ;(
>


I would do this a little differently.

INSERT INTO table ( starttime, endtime, val1, val(...) )
VALUES( old.endtime, now(), old.val1, old.val(...) );

UPDATE table
SET starttime = now(),
    val1 = new.val1,
    val... = new.val(...)
WHERE now() between starttime AND endtime;


This way your current record stays current and you simply insert history records.

Regards,
Richard Broersma Jr.


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

Предыдущее
От: Hans-Peter Oeri
Дата:
Сообщение: Implementation of a updateable, "temporal" view on data
Следующее
От: Hans-Peter Oeri
Дата:
Сообщение: Re: Implementation of a updateable, "temporal" view on data