Re: Trigger vs Rule - Mailing list pgsql-performance

From Niklas Johansson
Subject Re: Trigger vs Rule
Date
Msg-id 5DEF8AEF-9FBD-4C6E-88BD-FA90CB1BDF31@tele2.se
Whole thread Raw
In response to Re: Trigger vs Rule  (Niklas Johansson <spot@tele2.se>)
Responses Re: Trigger vs Rule  (Ключников А.С. <alexs@analytic.mv.ru>)
List pgsql-performance
On 2 apr 2006, at 23.08, Niklas Johansson wrote:

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


Sorry, I was bitten by the bedbug there: a plpgsql function needs a
little more than that to be functional :)

CREATE OR REPLACE FUNCTION exec_device_type() RETURNS trigger AS $$
BEGIN
    EXECUTE 'SELECT device_type' || OLD.type || '(OLD.id)';
    RETURN NEW/OLD/NULL; -- Depending on your application.
END;
$$ LANGUAGE plpgsql;

But really, you should consider reworking your schema structure.
Having a thousand functions doing almost the same thing is neither
efficient, nor maintainable.



Sincerely,

Niklas Johansson





pgsql-performance by date:

Previous
From: Brendan Duddridge
Date:
Subject: Re: Query using SeqScan instead of IndexScan
Next
From: Ключников А.С.
Date:
Subject: Re: Trigger vs Rule