Executes a SQL INSERT statement (adding a new row to a table), returning no result.

insert($connection as javatype:java.sql.Connection, $table as xs:string, $values as map(*)) ➔ item()?





A JDBC database connection established using sql:connect




The database table from which rows are to be updated




A map holding values for the new row





Notes on the Saxon implementation

Introduced in Saxon 9.9. Designed to supersede the extension instruction sql:insert. The saxon9-sql.jar file, distributed alongside the main JAR file, must be added to the classpath when these SQL extension functions are used.


The function executes a SQL INSERT statement (adding a new row to a table), and returns no result.

The $table argument names the database table to be updated. New values for selected columns are taken from the $values map.

The entries in the $values map are (name, value) pairs, where the name is a column name in the table being updated, and the value is the value for the column. The value should be an appropriate data type for the column (for example, xs:string for a VARCHAR column, xs:decimal for a DECIMAL column, etc).

Although the declared return type is item()?, the function always returns an empty sequence. The declared return type is designed to prevent the optimizer making unwarranted assumptions.

Because this function is executed for its side-effects, it is recommended to invoke it using the saxon:do extension instruction.


<saxon:do action="sql:insert($connection, 'book', map{'title': TITLE, 'author': AUTHOR, 'category': $category, 'price': PRICE, 'date': current-date()})"/>