webCOMAND

POSITION_IN_TREE()

Return the index of the object within an ordered hierarchical collection.  It is similar to POSITION_IN() for flat collections, except it will return the index of an object within a hierarchy, as displayed in Tree View.

NOTE: This function is not yet supported and will be introduced after hierarchical query optimizations are introduced.

Prototype

integer POSITION_IN_TREE(cpath $cpath, cpath $field = NULL)

Parameters

  • cpath - cPath, OID, DOID (ie. 123D) or UUID that references a:
    • Folder - If a folder or object that extends folder is specified and no field parameter is specified, the Folder's Contents field will be assumed.
    • Object - If a non-folder object is specified, then the field must be specified.
  • field - Optional Identifier of an ordered collection field, which is required when the cpath parameter references an object that is not a Folder.

Return

An integer that represents the object's index into the ordered collection.  If the object is not in the collection, NULL is returned, which can be useful when testing for an object's membership in a specific field in a WHERE clause or cPath filter.

Folder cPath Example

SELECT * FROM WebPage ORDER BY POSITION_IN_TREE(/Website/Content)

Folder OID Example

SELECT * FROM WebPage WHERE POSITION_IN_TREE(123)

Collection Field Example

SELECT * FROM WebPage ORDER BY POSITION_IN_TREE([:Location AND OID=456].WebPages)

Collection Field Example

SELECT * FROM WebPage ORDER BY POSITION_IN_TREE(456, WebPages)