postgresql logo
PostgreSQL v3.8.0, Mar 22 23

postgresql.Function

Explore with Pulumi AI

The postgresql.Function resource creates and manages a function on a PostgreSQL server.

Usage

import * as pulumi from "@pulumi/pulumi";
import * as postgresql from "@pulumi/postgresql";

const increment = new postgresql.Function("increment", {
    args: [{
        name: "i",
        type: "integer",
    }],
    body: `    BEGIN
        RETURN i + 1;
    END;

`,
    language: "plpgsql",
    returns: "integer",
});
import pulumi
import pulumi_postgresql as postgresql

increment = postgresql.Function("increment",
    args=[postgresql.FunctionArgArgs(
        name="i",
        type="integer",
    )],
    body="""    BEGIN
        RETURN i + 1;
    END;

""",
    language="plpgsql",
    returns="integer")
using System.Collections.Generic;
using Pulumi;
using PostgreSql = Pulumi.PostgreSql;

return await Deployment.RunAsync(() => 
{
    var increment = new PostgreSql.Function("increment", new()
    {
        Args = new[]
        {
            new PostgreSql.Inputs.FunctionArgArgs
            {
                Name = "i",
                Type = "integer",
            },
        },
        Body = @"    BEGIN
        RETURN i + 1;
    END;

",
        Language = "plpgsql",
        Returns = "integer",
    });

});
package main

import (
	"github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := postgresql.NewFunction(ctx, "increment", &postgresql.FunctionArgs{
			Args: postgresql.FunctionArgArray{
				&postgresql.FunctionArgArgs{
					Name: pulumi.String("i"),
					Type: pulumi.String("integer"),
				},
			},
			Body:     pulumi.String("    BEGIN\n        RETURN i + 1;\n    END;\n\n"),
			Language: pulumi.String("plpgsql"),
			Returns:  pulumi.String("integer"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.postgresql.Function;
import com.pulumi.postgresql.FunctionArgs;
import com.pulumi.postgresql.inputs.FunctionArgArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var increment = new Function("increment", FunctionArgs.builder()        
            .args(FunctionArgArgs.builder()
                .name("i")
                .type("integer")
                .build())
            .body("""
    BEGIN
        RETURN i + 1;
    END;

            """)
            .language("plpgsql")
            .returns("integer")
            .build());

    }
}
resources:
  increment:
    type: postgresql:Function
    properties:
      args:
        - name: i
          type: integer
      body: |2+
            BEGIN
                RETURN i + 1;
            END;

      language: plpgsql
      returns: integer

Create Function Resource

new Function(name: string, args: FunctionArgs, opts?: CustomResourceOptions);
@overload
def Function(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             args: Optional[Sequence[FunctionArgArgs]] = None,
             body: Optional[str] = None,
             database: Optional[str] = None,
             drop_cascade: Optional[bool] = None,
             language: Optional[str] = None,
             name: Optional[str] = None,
             returns: Optional[str] = None,
             schema: Optional[str] = None)
@overload
def Function(resource_name: str,
             args: FunctionArgs,
             opts: Optional[ResourceOptions] = None)
func NewFunction(ctx *Context, name string, args FunctionArgs, opts ...ResourceOption) (*Function, error)
public Function(string name, FunctionArgs args, CustomResourceOptions? opts = null)
public Function(String name, FunctionArgs args)
public Function(String name, FunctionArgs args, CustomResourceOptions options)
type: postgresql:Function
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args FunctionArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args FunctionArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args FunctionArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args FunctionArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args FunctionArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Function Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The Function resource accepts the following input properties:

Body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

Args List<Pulumi.PostgreSql.Inputs.FunctionArgArgs>

List of arguments for the function.

Database string

The database where the function is located. If not specified, the function is created in the current database.

DropCascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

Language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

Name string

The name of the argument.

Returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

Schema string

The schema where the function is located. If not specified, the function is created in the current schema.

Body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

Args []FunctionArgArgs

List of arguments for the function.

Database string

The database where the function is located. If not specified, the function is created in the current database.

DropCascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

Language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

Name string

The name of the argument.

Returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

Schema string

The schema where the function is located. If not specified, the function is created in the current schema.

body String

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

args List<FunctionArgArgs>

List of arguments for the function.

database String

The database where the function is located. If not specified, the function is created in the current database.

dropCascade Boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language String

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name String

The name of the argument.

returns String

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema String

The schema where the function is located. If not specified, the function is created in the current schema.

body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

args FunctionArgArgs[]

List of arguments for the function.

database string

The database where the function is located. If not specified, the function is created in the current database.

dropCascade boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name string

The name of the argument.

returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema string

The schema where the function is located. If not specified, the function is created in the current schema.

body str

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

args Sequence[FunctionArgArgs]

List of arguments for the function.

database str

The database where the function is located. If not specified, the function is created in the current database.

drop_cascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language str

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name str

The name of the argument.

returns str

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema str

The schema where the function is located. If not specified, the function is created in the current schema.

body String

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

args List<Property Map>

List of arguments for the function.

database String

The database where the function is located. If not specified, the function is created in the current database.

dropCascade Boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language String

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name String

The name of the argument.

returns String

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema String

The schema where the function is located. If not specified, the function is created in the current schema.

Outputs

All input properties are implicitly available as output properties. Additionally, the Function resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up Existing Function Resource

Get an existing Function resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: FunctionState, opts?: CustomResourceOptions): Function
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        args: Optional[Sequence[FunctionArgArgs]] = None,
        body: Optional[str] = None,
        database: Optional[str] = None,
        drop_cascade: Optional[bool] = None,
        language: Optional[str] = None,
        name: Optional[str] = None,
        returns: Optional[str] = None,
        schema: Optional[str] = None) -> Function
func GetFunction(ctx *Context, name string, id IDInput, state *FunctionState, opts ...ResourceOption) (*Function, error)
public static Function Get(string name, Input<string> id, FunctionState? state, CustomResourceOptions? opts = null)
public static Function get(String name, Output<String> id, FunctionState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Args List<Pulumi.PostgreSql.Inputs.FunctionArgArgs>

List of arguments for the function.

Body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

Database string

The database where the function is located. If not specified, the function is created in the current database.

DropCascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

Language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

Name string

The name of the argument.

Returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

Schema string

The schema where the function is located. If not specified, the function is created in the current schema.

Args []FunctionArgArgs

List of arguments for the function.

Body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

Database string

The database where the function is located. If not specified, the function is created in the current database.

DropCascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

Language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

Name string

The name of the argument.

Returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

Schema string

The schema where the function is located. If not specified, the function is created in the current schema.

args List<FunctionArgArgs>

List of arguments for the function.

body String

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

database String

The database where the function is located. If not specified, the function is created in the current database.

dropCascade Boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language String

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name String

The name of the argument.

returns String

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema String

The schema where the function is located. If not specified, the function is created in the current schema.

args FunctionArgArgs[]

List of arguments for the function.

body string

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

database string

The database where the function is located. If not specified, the function is created in the current database.

dropCascade boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language string

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name string

The name of the argument.

returns string

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema string

The schema where the function is located. If not specified, the function is created in the current schema.

args Sequence[FunctionArgArgs]

List of arguments for the function.

body str

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

database str

The database where the function is located. If not specified, the function is created in the current database.

drop_cascade bool

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language str

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name str

The name of the argument.

returns str

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema str

The schema where the function is located. If not specified, the function is created in the current schema.

args List<Property Map>

List of arguments for the function.

body String

Function body. This should be the body content withing the AS $$ and the final $$. It will also accept the AS $$ and $$ if added.

database String

The database where the function is located. If not specified, the function is created in the current database.

dropCascade Boolean

True to automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects. Default is false.

language String

The function programming language. Can be one of internal, sql, c, plpgsql. Default is plpgsql.

name String

The name of the argument.

returns String

Type that the function returns. It can be computed from the OUT arguments. Default is void.

schema String

The schema where the function is located. If not specified, the function is created in the current schema.

Supporting Types

FunctionArg

Type string

The type of the argument.

Default string

An expression to be used as default value if the parameter is not specified.

Mode string

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

Name string

The name of the argument.

Type string

The type of the argument.

Default string

An expression to be used as default value if the parameter is not specified.

Mode string

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

Name string

The name of the argument.

type String

The type of the argument.

default_ String

An expression to be used as default value if the parameter is not specified.

mode String

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

name String

The name of the argument.

type string

The type of the argument.

default string

An expression to be used as default value if the parameter is not specified.

mode string

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

name string

The name of the argument.

type str

The type of the argument.

default str

An expression to be used as default value if the parameter is not specified.

mode str

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

name str

The name of the argument.

type String

The type of the argument.

default String

An expression to be used as default value if the parameter is not specified.

mode String

Can be one of IN, INOUT, OUT, or VARIADIC. Default is IN.

name String

The name of the argument.

Package Details

Repository
PostgreSQL pulumi/pulumi-postgresql
License
Apache-2.0
Notes

This Pulumi package is based on the postgresql Terraform Provider.