Re: Trigger vs Rule

From: Niklas Johansson <spot(at)tele2(dot)se>
To: Ключников А(dot)С(dot) <alexs(at)analytic(dot)mv(dot)ru>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Trigger vs Rule
Date: 2006-04-02 21:08:44
Message-ID: 2EE594DC-5F83-4381-9045-CB2A10180023@tele2.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On 2 apr 2006, at 10.31, Ключников А.С. wrote:
> What is faster?
> One trigger with 1000 ELSE IF
> Or 1000 rules

Faster to write and easier to maintain would be to write a trigger
function in pl/pgsql which executes the right function dynamically:

CREATE OR REPLACE FUNCTION exec_device_type() RETURNS trigger AS $$
EXECUTE "SELECT device_type" || OLD.type || "(OLD.id)";
$$ LANGUAGE plpgsql;

Best would probably be to refactor your device_typeN() functions into
one, that would take N as an argument.

Sincerely,

Niklas Johansson

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2006-04-02 22:30:55 Re: Query using SeqScan instead of IndexScan
Previous Message Stephan Szabo 2006-04-02 19:46:55 Re: index not used again