[Dbix-class] Optimistic locking
David Wheeler
david at kineticode.com
Fri Aug 4 19:31:46 CEST 2006
On Aug 4, 2006, at 10:07, Dan Horne wrote:
> So, my question is: Is there any way to create such a pseudocolumn
> that can
> be populated as a result of the values of the other columns?
If you want to use a real column, you can add it to your table and
then add a trigger to the table to compute the hash. Something like
this (in PostgreSQL):
CREATE OR REPLACE FUNCTION hash_row() RETURNS trigger AS $$
NEW.hash = md5(NEW.foo || NEW.bar || NEW.baz);
RETURN NEW;
$$ LANGUAGE sql;
CREATE TRIGGER hash_row BEFORE UPDATE OR INSERT ON mytable
FOR EACH ROW EXECUTE PROCEDURE hash_row();
Best,
David
More information about the Dbix-class
mailing list