db.function: Register functions with a database connection

View source: R/db-function.R

db.functionR Documentation

Register functions with a database connection

Description

Register functions with a database connection

Usage

db.function(db, NAME, FUN)

Arguments

db

The database connection. S4 object of class "database".

NAME

The name to register the function under.

FUN

The function to register.

Details

Functions registered with a database connection can be referred to by NAME in SQL statements. To unregister a function NAME, pass NULL as the FUN argument. See examples.

Value

None.

Note

A current limitation is that arguments to functions inside SQL statements can only be referred to by position. In other words, constructs like argname=argvalue will not work.

Examples

db = db.open()
db.function(db, "multiply", `*`)
db.eval(db, "CREATE TABLE t(a REAL, b REAL)")
db.eval(db, "INSERT INTO t VALUES (?,?)", matrix(rnorm(200), 100, 2))
db.eval(db, "SELECT multiply(a, b) FROM t", df=TRUE)
db.function(db, "multiply", NULL)
## Not run: 
db.eval(db, "SELECT multiply(a, b) FROM t") # no such function: multiply

## End(Not run)

blueraleigh/db documentation built on Feb. 25, 2024, 9:13 a.m.