4.3.5 The put() Function

The fn:put() function stores a node as a new document at some URI. MonetDB/XQuery only supports file:// URIs here (though the file:// prefix itself may be omitted, since a filename is assumed as default) with the security restriction that the file path must be local. That is, it may not start with a slash, or drive letter, nor may it contain backwards paths (..). This means that the XML files produced by fn:put() will be located in the <gdk_dbfarm>/<dbname>/ directory, or one of its sub-directories. If the filepath provided as a parameter to fn:put() contains a sub-directory path, this sub-directory is created automatically.

The restriction on local filepaths is a securiy feature: otherwise it would be possible to overwrite any writable file in the server filesystem using XQuery queries that contain fn:put().

One of the interesting uses of fn:put() is to cache intermediate results produced by a costly query. A handly place to put these is the local tmp/ directory, as MonetDB/XQuery automatically removes all temporary documents that are older than an hour (see Temporary Documents). This way, your application does not need to worry about garbage collection.