Skip to content

Latest commit

 

History

History
91 lines (66 loc) · 2.49 KB

DdlPositionClausesRule.md

File metadata and controls

91 lines (66 loc) · 2.49 KB

<-- previous rule | overview | next rule -->

Break before WHERE clause etc.

Standardizes line breaks and indentation of keywords that start the clauses WHERE, GROUP BY, HAVING, as well as EXCEPT, INTERSECT and UNION.

Options

  • Break before WHERE / GROUP BY / HAVING: [Always]
  • Indent if breaking: [0]
  • Break before EXCEPT / INTERSECT / UNION: [Always]
  • Indent if breaking: [0]
  • The position of SELECT FROM after a UNION etc. can be changed with the rule 'Break before AS SELECT etc.'

Examples

define view entity C_AnyEntity
  as select from I_AnyEntity as AnyAlias

{
  key AnyAlias.AnyKeyField          as AnyKey,
      sum(AnyAlias.AnyNumericField) as AnySum,
      AnyAlias.UnitField            as Unit
}

where AnyAlias.AnyConditionField = 'X'
  and AnyAlias.AnyCategory       = 'A' group
by AnyAlias.AnyKeyField,
   AnyAlias.AnyNumericField,
   AnyAlias.UnitField having AnyAlias.AnyNumericField > 100

union all
  select from I_OtherEntity as OtherAlias

{
  key OtherAlias.OtherKeyField          as AnyKey,
      sum(OtherAlias.OtherNumericField) as AnySum,
      OtherAlias.OtherUnitField         as Unit
} where OtherAlias.OtherCategory = 'A'
     or OtherAlias.OtherCategory = 'B'

group by OtherAlias.OtherKeyField,
         OtherAlias.OtherNumericField,
         OtherAlias.OtherUnitField

Resulting code:

define view entity C_AnyEntity
  as select from I_AnyEntity as AnyAlias

{
  key AnyAlias.AnyKeyField          as AnyKey,
      sum(AnyAlias.AnyNumericField) as AnySum,
      AnyAlias.UnitField            as Unit
}

where AnyAlias.AnyConditionField = 'X'
  and AnyAlias.AnyCategory       = 'A'
group by AnyAlias.AnyKeyField,
         AnyAlias.AnyNumericField,
         AnyAlias.UnitField
having AnyAlias.AnyNumericField > 100

union all
  select from I_OtherEntity as OtherAlias

{
  key OtherAlias.OtherKeyField          as AnyKey,
      sum(OtherAlias.OtherNumericField) as AnySum,
      OtherAlias.OtherUnitField         as Unit
}
where OtherAlias.OtherCategory = 'A'
   or OtherAlias.OtherCategory = 'B'

group by OtherAlias.OtherKeyField,
         OtherAlias.OtherNumericField,
         OtherAlias.OtherUnitField

Related code