Re: Trigger vs Rule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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






[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux