Loading TOC...

MarkLogic 9 Product Documentation
view functions

The table below lists all the view built-in functions (in this namespace: http://marklogic.com/xdmp/view).

The views module is used to create and manage SQL schemas and views. This API only creates and manages Range Views, as described in Creating Range Views in the SQL Data Modeling Guide. The functions in this API will not work on Template Views, as described in Creating Template Views in the SQL Data Modeling Guide.

A schema defines a logical scoping for views. A schema has a unique ID, a name (which must also be unique), and a collection of views. During SQL execution, the schema provides the naming context for its views, which enables you have have multiple views of the same name in different schemas. The default schema is called "main". Even though it is a default, you must create the "main" schema before it can be used.

A view is an abstraction of a SQL "table." However, unlike in a relational database, a view in MarkLogic server is implemented on top of element range indexes. A view consists of a unique ID, a name (which must be unique in the context of a particular schema), a view scope, and a sequence of column specifications. Each column has a name and a range index reference. The range index for each column must be created before creating the view. The view scope is used to constrain the subset of the database to which the view applies. The view scope can either limit rows in the view to documents with a specific element (localname + namespace) or to documents in a particular collection.

The views function module is installed as the following file:

  • install_dir/Modules/MarkLogic/views.xqy

where install_dir is the directory in which MarkLogic Server is installed.

To use the views.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

import module namespace view="http://marklogic.com/xdmp/view" at "/MarkLogic/views.xqy";

You must have the view-admin role to execute the functions in the View library.

37 functions
Function name Description
view:add-column This function adds column specifications to the current set of column specifications on the named view in the named schema.
view:add-field This function adds a field to the named view.
view:add-permissions This function adds permissions to those already set for the named view in the named schema specification.
view:collection This function return the URI of the protected collection holding all the views.
view:collection-view-scope This function constructs a new collection-style view scope specification.
view:column This function constructs a new column specification.
view:columns This function returns the sequence of column specifications set in the named view in the named schema.
view:create This function creates a new view in the specified schema specification.
view:element-view-scope This function constructs a new element-style view scope specification.
view:field This function constructs a new element-style field specification for the named field.
view:fields This function returns the fields set on the named view.
view:get This function returns the named view from the named schema specification.
view:get-bindings This function generates a binding map suitable for use with cts:parse from the named view.
view:get-by-id This function returns the view with the specified id.
view:get-column This function returns the named column specification set in the named view in the named schema.
view:get-field This function returns the element specification for the named field.
view:get-permissions This function returns the permissions set on the specified view.
view:get-view-scope This function returns the scope of the named view in the named schema.
view:remove This function removes the named view from the named schema specification.
view:remove-by-id This function removes the view with the specified id.
view:remove-column This function removes a column specification from the named view in the named schema.
view:remove-field This function removes a field from the named view.
view:remove-permissions This function removes permissions from those set for the named view in the named schema specification.
view:schema-add-permissions This function adds permissions to the specified schema specification.
view:schema-create This function creates a new relational schema in the Schema database.
view:schema-get This function returns the named schema specification document.
view:schema-get-permissions This function returns the permissions set on the specified schema.
view:schema-remove This function removes the specified schema.
view:schema-remove-permissions This function removes permissions from the specified schema specification.
view:schema-set-permissions This function sets permissions on the specified schema specification.
view:schemas This function returns all of the schema specifications.
view:set-columns This function replaces the current set of column specifications on the named view in the named schema with a new set of columns.
view:set-fields This function sets the specified fields on the specified view.
view:set-name This function renames the named view in the named schema specification.
view:set-permissions This function sets the permissions for the named view in the named schema specification.
view:set-view-scope This function sets the scope of the named view in the named schema specification.
view:views This function returns all of the view specifications in the named schema.