Trigger or Function

Поиск
Список
Период
Сортировка
От alan
Тема Trigger or Function
Дата
Msg-id cf38a540-20ef-45d7-b593-2a6ec3337a95@j15g2000yqf.googlegroups.com
обсуждение исходный текст
Ответы Re: Trigger or Function
Список pgsql-performance
Hello,
I'm a postgres newbie and am wondering what's the best way to do this.

I am gathering some data and will be inserting to a table once daily.
The table is quite simple but I want the updates to be as efficient as
possible since
this db is part of a big data project.

Say I have a table with these columns:
| Date | Hostname | DayVal | WeekAvg | MonthAvg |

When I insert a new row I have the values for Date, Hostname, DayVal.
Is it possible to define the table is such a way that the WeekAvg and
MonthAvg
are automatically updated as follows?
  WeekAvg = current rows DayVal plus the sum of DayVal for the
previous 6 rows.
 MonthAvg = current row's DayVal plus the sum of DayVal for the
previous 29 rows.

Should I place the logic in a Trigger or in a Function?
Does someone have an example or a link showing how I could set this
up?

Regards,
Alan

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

Предыдущее
От: lars
Дата:
Сообщение: Re: UPDATEDs slowing SELECTs in a fully cached database
Следующее
От: Clem Dickey
Дата:
Сообщение: Re: Planner choosing NestedLoop, although it is slower...