Hi,

So to sum it up it seems that:
> "SELECT trigger is fired whenever the dbms makes a lookup on a table while
> executing the SELECT statement."
>

I will write: "A BEFORE SELECT trigger is fired just before the database
engine tries to read from the table."

My final question is that what use cases do people have for using the
> select trigger?
>
The only one I can come up with is to do some logging/statistics.
> The documentation says:"A BEFORE SELECT trigger can be used to update a
> table on demand"
> But I can't figure out what that could mean.
> Maybe keeping LAST_ACCESSED column up-to-date?
>

It can be used as a replacement for a "materialized view". As an example,
if you have a regular table INVOICES, and you regularly want to query for
SUM(AMOUNT) FROM INVOICES WHERE CUSTOMER_ID=?. You could create a table
CUSTOMER_INVOICE_SUM or so. On this table, you could create a BEFORE SELECT
trigger that updates the table whenever it is queried, but only if the
INVOICES table changed. The trigger would lazily update the
CUSTOMER_INVOICE_SUM table.

My plan is to use a similar mechanism for (PostgreSQL) metadata tables in
the future. Currently, some of the metadata tables dynamically generated
whenever they are queried. It would be better if they are regular tables,
and only updated when needed.

Regards,
Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to