Re: pl/pgsql trigger function - compare *most* columns in NEW vs. OLD

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: pl/pgsql trigger function - compare *most* columns in NEW vs. OLD
Дата
Msg-id CAHyXU0xLrLjgF2aDNQK9tQwp2aaGEUjhmwY3f6maSnA7zcNCdg@mail.gmail.com
обсуждение исходный текст
Ответ на pl/pgsql trigger function - compare *most* columns in NEW vs. OLD  (Mike Blackwell <mike.blackwell@rrd.com>)
Список pgsql-general
On Thu, Dec 18, 2014 at 12:16 PM, Mike Blackwell <mike.blackwell@rrd.com> wrote:
> Is there a simple notation for comparing most columns in the new and old
> records in a pl/pgsql trigger function?  Something like
>
> (new.b, new.c, new.d) = (old.b, old.c, old.d)
>
> works to compare all the columns except 'a', but is fragile in that it needs
> to be updated any time a column is added to the table, and is rather messy
> looking when the actual table has many columns.
>
> Is there a better approach to detecting a change in any column except a few
> specific ones?

yes, via hstore

declare
  diff hstore;
  ignore_columns text[] default array['col1', 'col2'];
begin
  diff := hstore(new) - hstore(old) - ignore_columns;
...

boom!

merlin


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

Предыдущее
От: "Cristian Iturrieta"
Дата:
Сообщение: Postgresql 9.2, Memoy cache usage.
Следующее
От: Robert DiFalco
Дата:
Сообщение: Combining two queries