createFUNCTION {pgTools}R Documentation

Generate a PostgreSQL CREATE FUNCTION statement, optionally execute the statement if con is not NULL.

Description

Generate a PostgreSQL CREATE FUNCTION statement, optionally execute the statement if con is not NULL.

Usage

createFUNCTION(
  name,
  args = NULL,
  or_replace = FALSE,
  returns = NULL,
  returns_table = NULL,
  language = "SQL",
  definition,
  con = NULL
)

Arguments

name

A string, the "name" parameter for PostgreSQL CREATE FUNCTION.

args

A named list, names are the argument names, values are strings with the argument data types.

or_replace

TRUE/FALSE, if TRUE, adds "OR REPLACE" to PostgreSQL CREATE FUNCTION statement.

returns

A string, the "returns" parameter for PostgreSQL CREATE FUNCTION.

returns_table

A named list, names are the return table column names, values are strings with the return table data types.

language

A string, the "language" parameter for PostgreSQL CREATE FUNCTION.

definition

A string, the "definition" parameter for PostgreSQL CREATE FUNCTION.

con

A database connection that can be passed to DBI::dbSendQuery/DBI::dbGetQuery.

Value

A string, PostgreSQL CREATE PROCEDURE statement; or the results retrieved by DBI::dbSendQuery after executing the statement.

Examples

createFUNCTION(
name = "sample_add",
args = list(a = "INTEGER", b = "INTEGER"),
returns = "INT",
language = "plpgsql",
definition = "BEGIN RETURN sample_add.a + sample_add.b; END;"
)

[Package pgTools version 1.0.2 Index]