WHERE

The selection — boolean expressions over features, the numeric and string comparators, tolerances, has-value tests, relation paths with all/any/count, and relation aggregates.

WHERE selects the objects a query returns. Its argument is a boolean expression over the object's features. The same expression language is used, without the WHERE keyword, as a bare query, in the if and select conditions of BVL and BCL, in the WHERE of BUL, and inside nested relation queries.

Syntax#

Text#
GET <features> WHERE <condition>
<condition>                       // without GET: a bare selection

WHERE needs a GET in front of it. A query that only selects is written as the condition alone.

BQL#
GET qid, attribute.Name WHERE type = IFCWALL AND property.Pset_WallCommon.IsExternal = true
BQL#
type = IFCWALL AND property.Pset_WallCommon.IsExternal = true

Conditions#

A condition is one of:

Form Meaning
<feature> <comparator> <value> Compare a feature's value (comparisons, string comparators).
<feature> The object has a value for the feature (has-value).
type …, suggestedType … Class tests with inheritance (Types).
qid … Identity tests (qid).
<relation>.<condition>, <relation>.any(…) Conditions on related objects (paths).
<relation>(<aggregate> WHERE …) <comparator> <value> Aggregates over related objects (relation aggregates).
model.<condition> Conditions on the model (model#conditions).
ALL Every object.
CLASHES_WITH(…), geometry:…, sem:…, PART_OF(…), nav:…, TEXT_MATCHES(…), geoReference … Spatial, semantic and text predicates (Spatial and advanced).

Logic#

Conditions combine with AND, OR and NOT; NOT binds tightest, then AND, then OR. Parentheses group.

BQL#
GET qid WHERE (type = IFCWALL OR type = IFCSLAB) AND NOT (property.Pset_WallCommon.IsExternal = true)

NOT also has dedicated forms: type NOT IN (...), qid NOT IN (...), attribute.Name NOT IN ("a", "b").

Comparisons#

Comparator Right-hand side Example
= != A number (with optional unit), string, boolean, null, a feature or an arithmetic expression, or a parameter quantity.Qto_DoorBaseQuantities.Width = 0.9 m
< <= > >= A number with optional unit, a feature, an expression, or a parameter aabb.height > 3 m
IN (…) NOT IN (…) A list of numbers, booleans or strings attribute.Name IN ("Wall-1", "Wall-2")
IN $p NOT IN $p A parameter bound to an array property.*.FireRating IN $ratings
BETWEEN a AND b, BETWEEN (a, b) Two numbers with optional units, both ends inclusive; or BETWEEN $range aabb.height BETWEEN 2.4 m AND 3 m

Both sides of a numeric comparison take arithmetic (+ - * /, ABS(...), parentheses) with automatic unit handling, so two features can be compared with each other. A left side that starts with ( is fine: (a + b) > c.

BQL#
GET qid WHERE type = IFCWALL AND quantity.Qto_WallBaseQuantities.NetVolume > calculated.quantity.volume * 1.1
BQL#
GET qid, aabb.height WHERE type = IFCDOOR AND aabb.height BETWEEN 2.0 m AND 2.4 m

A = or != on a decimal number is an exact floating-point comparison and easily misses; the validator warns and suggests BETWEEN or a tolerance.

Tolerances: WITHIN#

WITHIN attaches a tolerance to = and != on numbers: a = b WITHIN 5 % is relative to the right-hand side (|a − b| ≤ 5 % of |b|), a = b WITHIN 5 mm is absolute and must match the dimension of the operands, and a != b WITHIN … holds when the deviation exceeds the tolerance. A bare number is a tolerance in the operands' own dimension, only meaningful when they are unitless.

BQL#
GET qid, quantity.Qto_WallBaseQuantities.NetVolume, calculated.quantity.volume
WHERE type = IFCWALL AND quantity.Qto_WallBaseQuantities.NetVolume != calculated.quantity.volume WITHIN 2 %

String comparators#

String comparisons are case-insensitive; prefix the comparator with CS for a case-sensitive test.

Comparator Meaning Example
= != Equal, not equal (case-insensitive) attribute.Name = "Level 1"
CS = CS != Case-sensitive equal, not equal attribute.Name CS = "Level 1"
IN ("a", "b"), CS IN, NOT IN, CS NOT IN Membership layer.name IN ("A-WALL", "A-DOOR")
CONTAINS, CS CONTAINS Substring attribute.Name CONTAINS "wall"
STARTS_WITH, CS STARTS_WITH Prefix attribute.Name STARTS_WITH "Basic"
ENDS_WITH, CS ENDS_WITH Suffix attribute.Name ENDS_WITH "01"
MATCHES_REGEX, CS MATCHES_REGEX Regular expression over the whole value property.*.Nlsfb MATCHES_REGEX "^[0-9][0-9][.][0-9][0-9]$"
MATCHES "text" [FUZZY [n]] Analysed full-text match through the text index; FUZZY allows up to n edits (1 or 2). Needs text indexing on the instance. attribute.Name MATCHES "brandwerend" FUZZY 1
LENGTH <op> n Length of the string, with =, !=, <, <=, >, >= attribute.Name LENGTH > 20

The right-hand string of CONTAINS, STARTS_WITH, ENDS_WITH, MATCHES_REGEX, MATCHES, CS = and CS != may be a parameter (CONTAINS $text). An invalid regular expression is reported at validation and fails the query at runtime.

BQL#
GET qid, attribute.Name WHERE type = IFCSPACE AND attribute.LongName CONTAINS "kitchen" AND attribute.Name LENGTH <= 8

Booleans and null#

Boolean properties compare with true and false; = null selects objects that have no value for the feature, != null those that have one.

BQL#
GET qid, attribute.Name WHERE type = IFCDOOR AND property.Pset_DoorCommon.FireRating = null

Has-value#

A feature on its own, without a comparator, is true when the object has a value for it. property.*.FireRating selects every object with a FireRating in any property set; the negation NOT property.*.FireRating selects the rest.

BQL#
GET qid, property.*.FireRating WHERE type = IFCDOOR AND property.*.FireRating

A property path needs a member: property.Pset_WallCommon alone is a syntax error. To test whether a set exists, use the meta feature in GET and group on it; .meta features cannot be filtered on.

Types#

type tests the IFC class including subclasses; NI disables inheritance. The forms are type = IFCWALL, type != IFCWALL, type IN (IFCWALL, IFCDOOR), type NOT IN (...), type IN $types, and type NI = IFCWALL. suggestedType takes the same forms. Class names are upper case; an unknown name is a validation warning and a runtime error (BimWorksQueryError.UNKNOWN_TYPE). Details on Types.

Qids#

qid = "<vid>-<oid>", qid IN ("…", "…"), qid NOT IN (...) and qid IN $selection select by identity. A qid literal is the version UUID, a dash and the oid; it may be written bare or quoted, and a version with several oids is written <uuid>[oid, oid].

BQL#
GET qid, attribute.Name WHERE qid IN ("797e993c-a87f-4aa7-9587-c59d30ec5c4e-1316", "797e993c-a87f-4aa7-9587-c59d30ec5c4e-1420")

Paths to related objects#

A relation name followed by a dot applies the rest of the condition to the related object(s). Single-target relations: project, site, building, buildingStorey, space, containedIn, parent, decomposes, typeObject, relatedBuildingElement, own. Multi-target relations: children, system, zone, port, spaceBoundary; these take a quantifier: .all(<condition>), .any(<condition>) or .count(<condition>) <comparator> <n>. Followed by a dot, a multi-target relation compares like .any: zone.attribute.Name = "Lab" holds when one of the object's zones is named Lab. zone.attribute.Name = null holds when none of them has a name or the object is in no zone, the same as NOT zone.attribute.Name. Paths chain: spaceBoundary.relatedBuildingElement.type = IFCWINDOW.

BQL#
GET qid, attribute.Name WHERE type = IFCDOOR AND buildingStorey.attribute.Name = "Level 1"
BQL#
GET qid, attribute.Name WHERE type = IFCSPACE AND children.count(type = IFCFURNISHINGELEMENT) >= 3

The relations and what they traverse are on Sub-features and relations; the storey and type-object shortcuts have their own pages (Building storeys, Type objects).

Relation aggregates#

A multi-target relation followed by one numeric aggregate in parentheses is a number per object and can be compared like any feature: spaceBoundary(SUM(quantity.*.Area) WHERE type = IFCWINDOW). The aggregate's argument is evaluated on each related object; the optional WHERE filters the related set. SUM over an empty set is 0; the other aggregates have no value then. The same form is a GET item (get#nested).

BQL#
GET qid, attribute.Name
WHERE type = IFCSPACE AND calculated.quantity.floorArea * 0.1 > spaceBoundary(SUM(quantity.*.Area) WHERE type = IFCWINDOW)

COUNT(<condition>) is also a WHERE operand: the number of objects in the queried models that match the condition.

Model conditions#

model.ifcVersion = IFC4, model.discipline IN (ARCHITECTURAL, STRUCTURAL) and model.count(<condition>) > n select objects by a property of the model they belong to; see model#conditions.

Parameters#

$name stands for a value supplied at run time and can replace a literal in nearly every position: = $x, > $min, IN $values, BETWEEN $lo AND $hi, BETWEEN $range, CONTAINS $text, type IN $types, qid IN $selection, and as the argument of the spatial functions. Binding is on using#parameters.

Validation notes#

  • WHERE without GET is a syntax error; a bare condition is the intended form.
  • Unknown IFC class names and unknown attribute names are reported with a did-you-mean; the query fails at run time.
  • BETWEEN with the lower bound above the upper bound matches nothing.
  • .meta features are selectable, not filterable.
  • A feature that is neither aggregated nor a group key in a grouped query returns the value of an arbitrary member of the group.

Used in#