sql:insert

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()?

Arguments

 

$connection

javatype:java.sql.Connection

A JDBC database connection established using sql:connect

 

$table

xs:string

The database table from which rows are to be updated

 

$values

map(*)

A map holding values for the new row

Result

item()?

Namespace

http://saxon.sf.net/sql

Saxon availability

Implemented since Saxon 9.9. Requires Saxon-PE or Saxon-EE. Available for Java only.

Notes on the Saxon implementation

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

Details

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.

Example:

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