Skip to content

HowToCalculatedField

Carlo Barazzetta edited this page Jan 20, 2017 · 1 revision

How to define a Calculated Field

Please refer to here for general information about models.

Kitto allows you to define fields as the result of a SQL expression calculated on the fly. These fields do not exist in the underlying database table but are needed in the application.

Use the Expression node: expressions may contain macros, and particularly database-scope macros (those with a DB. prefix) to help writing database-independent code. Fields must be qualified using the standard {Q} qualifier.

Example from TasKitto

# model Activity.yaml
ModelName: ACTIVITY
...
Fields:
....
  START_TIME: Time
  END_TIME: Time
  DURATION: Float
    DisplayWidth: 8
    Expression: |
      case
        when ({Q}START_TIME is null) or ({Q}END_TIME is null) then 0
        else ({Q}END_TIME - {Q}START_TIME) / 3600
      end
Clone this wiki locally