plpgsql

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package plpgsql provides PL/pgSQL function builder types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListObjectsFunctionHeader

func ListObjectsFunctionHeader(objectType, relation, features string) []string

ListObjectsFunctionHeader creates header comments for a list_objects function.

func ListObjectsReturns

func ListObjectsReturns() string

ListObjectsReturns returns the standard RETURNS clause for list_objects.

func ListSubjectsFunctionHeader

func ListSubjectsFunctionHeader(objectType, relation, features string) []string

ListSubjectsFunctionHeader creates header comments for a list_subjects function.

func ListSubjectsReturns

func ListSubjectsReturns() string

ListSubjectsReturns returns the standard RETURNS clause for list_subjects.

Types

type Assign

type Assign struct {
	Name  string
	Value sqldsl.Expr
}

Assign renders name := value;

func (Assign) StmtSQL

func (a Assign) StmtSQL() string

type Comment

type Comment struct {
	Text string
}

Comment renders a SQL comment line.

func (Comment) StmtSQL

func (c Comment) StmtSQL() string

type Decl

type Decl struct {
	Name string
	Type string
}

Decl represents a DECLARE variable declaration.

type FuncArg

type FuncArg struct {
	Name    string
	Type    string
	Default sqldsl.Expr // nil means no default
}

FuncArg represents a function argument with optional default value.

func ListObjectsArgs

func ListObjectsArgs() []FuncArg

ListObjectsArgs returns the standard arguments for a list_objects function.

func ListObjectsDispatcherArgs

func ListObjectsDispatcherArgs() []FuncArg

ListObjectsDispatcherArgs returns the arguments for the list_accessible_objects dispatcher.

func ListSubjectsArgs

func ListSubjectsArgs() []FuncArg

ListSubjectsArgs returns the standard arguments for a list_subjects function.

func ListSubjectsDispatcherArgs

func ListSubjectsDispatcherArgs() []FuncArg

ListSubjectsDispatcherArgs returns the arguments for the list_accessible_subjects dispatcher.

type If

type If struct {
	Cond sqldsl.Expr
	Then []Stmt
	Else []Stmt
}

If renders IF cond THEN ... [ELSE ...] END IF;

func (If) StmtSQL

func (i If) StmtSQL() string

type PlpgsqlFunction

type PlpgsqlFunction struct {
	Name    string
	Args    []FuncArg
	Returns string
	Decls   []Decl
	Body    []Stmt
	Header  []string // Comment lines at the top of the function (without -- prefix)
}

PlpgsqlFunction represents a complete PL/pgSQL function definition.

func (PlpgsqlFunction) SQL

func (f PlpgsqlFunction) SQL() string

SQL renders the complete CREATE OR REPLACE FUNCTION statement.

type Raise

type Raise struct {
	Message string
	ErrCode string
}

Raise renders RAISE EXCEPTION 'message' USING ERRCODE = 'code';

func (Raise) StmtSQL

func (r Raise) StmtSQL() string

type RawStmt

type RawStmt struct {
	SQLText string
}

RawStmt is an escape hatch for SQL that doesn't map cleanly to typed constructs. Use sparingly.

func (RawStmt) StmtSQL

func (r RawStmt) StmtSQL() string

type Return

type Return struct{}

Return renders a bare RETURN; statement.

func (Return) StmtSQL

func (Return) StmtSQL() string

type ReturnInt

type ReturnInt struct {
	Value int
}

ReturnInt renders RETURN <int>; as a convenience.

func (ReturnInt) StmtSQL

func (r ReturnInt) StmtSQL() string

type ReturnQuery

type ReturnQuery struct {
	Query string // Already-rendered SQL query
}

ReturnQuery renders RETURN QUERY <query>;

func (ReturnQuery) StmtSQL

func (r ReturnQuery) StmtSQL() string

type ReturnValue

type ReturnValue struct {
	Value sqldsl.Expr
}

ReturnValue renders RETURN <expr>;

func (ReturnValue) StmtSQL

func (r ReturnValue) StmtSQL() string

type SelectInto

type SelectInto struct {
	Query    sqldsl.SQLer // The SELECT query
	Variable string       // Variable name to select into
}

SelectInto renders SELECT ... INTO variable; Used for assigning query results to PL/pgSQL variables.

func (SelectInto) StmtSQL

func (s SelectInto) StmtSQL() string

type SqlFunction

type SqlFunction struct {
	Name    string
	Args    []FuncArg
	Returns string
	Body    sqldsl.SQLer // The body expression (e.g., a SelectStmt or function call)
	Header  []string     // Comment lines at the top of the function (without -- prefix)
}

SqlFunction represents a simple SQL function (LANGUAGE sql). Unlike PlpgsqlFunction, this renders a single SELECT expression as the body.

func (SqlFunction) SQL

func (f SqlFunction) SQL() string

SQL renders the complete CREATE OR REPLACE FUNCTION statement as LANGUAGE sql.

type Stmt

type Stmt interface {
	StmtSQL() string
}

Stmt is a PL/pgSQL statement that can be rendered to SQL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL