Loading TOC...

xdmp.sql

xdmp.sql(
   $sql as String,
   [$options as String[]]
) as ValueIterator

Summary

Executes an ad hoc SQL query. This function is for testing your SQL views when data modeling; it is not intended to be used directly in applications.

Parameters
$sql The SQL statement to be executed.
$options Options. Available options are:

array

Return the result as a sequence of array values (json:array).

format

Return the results as formatted strings.

map

Return the result as a sequence of map values, where the key is the column name.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-sql

Usage Notes

Only one of the "map" and "array" options may be specified. If neither is specified, the default is "array". If the "format" option is specified, the output will be formatted, regardless of whether "array" or "map" was selected.

The first tuple returned will always be one consisting of the column names.

Example

xdmp.sql("select title,author from books limit 4", "format");
==>
| title| author|
| The C++ Programming Language| Bjarne Stroustrup|
| Modern Information Retrieval| Ricardo Baeza-Yates|
| Modern Information Retrieval| Berthier Ribeiro-Neto|
| Unicode Demystified| Richard Gillam|

Example

xdmp.toJSON(xdmp.sql("select title,author from books limit 4", "array"));
==>
[["title", "author"],
 ["The C++ Programming Language", "Bjarne Stroustrup"],
 ["Modern Information Retrieval", "Ricardo Baeza-Yates"],
 ["Modern Information Retrieval", "Berthier Ribeiro-Neto"],
 ["Unicode Demystified", "Richard Gillam"]
]

Example

xdmp.toJSON(xdmp.sql("select title,author from books limit 4", "map"));
==>
[{"title", "author"},
 {"The C++ Programming Language", "Bjarne Stroustrup"},
 {"Modern Information Retrieval", "Ricardo Baeza-Yates"},
 {"Modern Information Retrieval", "Berthier Ribeiro-Neto"},
 {"Unicode Demystified", "Richard Gillam"}
]

Example

var res = new Array();
for (var row of xdmp.sql("select title,author from books limit 4")) {
  res.push(fn.concat("Title=", row[0],"; Author=", row[1])); };
==>
Title=title, Author=author
Title=The C++ Programming Language; Author=Bjarne Stroustrup
Title=Modern Information Retrieval; Author=Ricardo Baeza-Yates
Title=Modern Information Retrieval; Author=Berthier Ribeiro-Neto
Title=Unicode Demystified; Author=Richard Gillam

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy