Re: Function or Field? - Mailing list pgsql-sql

From Tambet Matiisen
Subject Re: Function or Field?
Date
Msg-id A66A11DBF5525341AEF6B8DE39CDE77008807E@black.aprote.com
Whole thread Raw
In response to Function or Field?  (lucas@presserv.org)
List pgsql-sql
>
> Hi.
> What is the better way to store the last record for a translation???
> I.E:
>  The data for the last product vendding.
>  What is better:
>  a) Create a field in "product" table and create a Trigger
> (before insert or update into vendding table) to alter this field.
>  b) Create a view or function that check the all venddings
> (in vendding table) for the specified product and return the
> last vendding information?
>

You could also use "computed field" approach described here (see Tip):
http://www.postgresql.org/docs/8.0/interactive/xfunc-sql.html#AEN29483

This allows you to do just what seems simpler and change later on.
No need to touch any other SQL code.

Keep in mind that when using triggers, every update generates a dead
tuple
both in products table and in all indexes. You need to VACUUM and
REINDEX
regularly. Been there, done that.
 Tambet


pgsql-sql by date:

Previous
From: lucas@presserv.org
Date:
Subject: Re: Record Log Trigger
Next
From: Frank Bax
Date:
Subject: Re: Function or Field?