How To Add A Calculated Column To A Table

How To Add A Calculated Column To A Table

book

Article ID: KB0076094

calendar_today

Updated On:

Products Versions
TIBCO Live Datamart -

Description

Often a field needs to be updated with some calculation instead of a simple copy of input data. This requires using insert and update field rules in the Live Datamart Table lvconf file.

Resolution

For example, here's how to add a field that counts the number of updates to a row, starting at one on insert and incrementing each update.

In the lvconf, add:

1. Add integer field "MyChanges" to the table schema.

2. Add a field rule for that field.
<field-rules>
  <rule>
    <default>
      <insert field="MyChanges">1</insert>
      <update field="MyChanges">old.MyChanges+1</update>
    </default>
  </rule>
</field-rules>

This rule does not reference any input data, but instead uses an expression to change the value with each update. The expression may reference input data or the field's currently stored value in order to calculate the new value.

Issue/Introduction

A code example of a LiveView field that is inserted and updated by an expressions only.