<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.sql.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.sql</api:function-name><api:suggest>xdmp.sql</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>sql</api:suggest><api:function-link mode="xquery" fullname="xdmp:sql">/apidoc/8.0/xdmp:sql.xml</api:function-link><api:function mode="javascript" name="sql" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.sql"><api: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.
</api:summary><api:params><api:param name="sql" type="xs:string"><api:param-description>
    The SQL statement to be executed.
  </api:param-description><api:param-name>sql</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options. Available options are:
    <dl xmlns="http://www.w3.org/1999/xhtml">
    <dt><p>array</p></dt><dd>Return the result as a sequence of array
    values (<code>json:array</code>).</dd>
    <dt><p>format</p></dt><dd>Return the results as formatted strings.</dd>
    <dt><p>map</p></dt><dd>Return the result as a sequence of map values,
    where the key is the column name.</dd>
    <!-- <dt><p>limit=<em>N</em></p></dt>
    <dd>Return no more than <em>N</em> tuples.</dd> -->
    </dl>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-sql</code></p>
</api:privilege><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">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.
</p>
<p xmlns="http://www.w3.org/1999/xhtml">The first tuple returned will always be one consisting of the column names.
<!-- This tuple is not included in the limit count. -->
</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.sql("select title,author from books limit 4", "format");
==&gt;
| title| author|
| The C++ Programming Language| Bjarne Stroustrup|
| Modern Information Retrieval| Ricardo Baeza-Yates|
| Modern Information Retrieval| Berthier Ribeiro-Neto|
| Unicode Demystified| Richard Gillam|
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.toJSON(xdmp.sql("select title,author from books limit 4", "array"));
==&gt;
[{"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"}
]
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
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])); };
==&gt;
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
</pre></api:example></api:function></api:function-page>