Search Postgresql Archives

Generic timestamp function for updates where field names vary

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

 



The pagila database has generic trigger function called last_updated() (shown
below) which is used to update timestamp columns in various tables. The
reason I can't use the function 'as is' for my own purposes is that in my
app the timestamp fields are not all named alike. The field names do follow
a pattern, two example names would be "user_datem "and "item_datem". I know
I could change my db so that all these timestamp fields are named "datem",
but I'd prefer to keep the names distinct, and of course I don't want to
create a tigger funtion for each table. Using the pagila trigger function as
a starting point, can someone suggest a solution? I am pretty sure that a
simple solution would be to pass in the prefix value, and concatenate with
the common "_datem".  Or is there a better solution? I will give the
approach I've outlined a try, but I'm not even sure it's doable (primarliy,
using the contatenated field name inplace of the "last-update" in
"NEW.last_update = CURRENT_TIMESTAMP;", that's just stuff I've not done in
plpgsql)...I'm all thumbs with plpgsql syntax, so anyone that wants to lay a
solution down would be helping out a lot.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux