PostgreSQL Source Code  git master
plpgsql.h File Reference
#include "access/xact.h"
#include "commands/event_trigger.h"
#include "commands/trigger.h"
#include "executor/spi.h"
#include "utils/expandedrecord.h"
#include "utils/typcache.h"
Include dependency graph for plpgsql.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PLpgSQL_type
 
struct  PLpgSQL_expr
 
struct  PLpgSQL_datum
 
struct  PLpgSQL_variable
 
struct  PLpgSQL_var
 
struct  PLpgSQL_row
 
struct  PLpgSQL_rec
 
struct  PLpgSQL_recfield
 
struct  PLpgSQL_nsitem
 
struct  PLpgSQL_stmt
 
struct  PLpgSQL_condition
 
struct  PLpgSQL_exception_block
 
struct  PLpgSQL_exception
 
struct  PLpgSQL_stmt_block
 
struct  PLpgSQL_stmt_assign
 
struct  PLpgSQL_stmt_perform
 
struct  PLpgSQL_stmt_call
 
struct  PLpgSQL_stmt_commit
 
struct  PLpgSQL_stmt_rollback
 
struct  PLpgSQL_diag_item
 
struct  PLpgSQL_stmt_getdiag
 
struct  PLpgSQL_stmt_if
 
struct  PLpgSQL_if_elsif
 
struct  PLpgSQL_stmt_case
 
struct  PLpgSQL_case_when
 
struct  PLpgSQL_stmt_loop
 
struct  PLpgSQL_stmt_while
 
struct  PLpgSQL_stmt_fori
 
struct  PLpgSQL_stmt_forq
 
struct  PLpgSQL_stmt_fors
 
struct  PLpgSQL_stmt_forc
 
struct  PLpgSQL_stmt_dynfors
 
struct  PLpgSQL_stmt_foreach_a
 
struct  PLpgSQL_stmt_open
 
struct  PLpgSQL_stmt_fetch
 
struct  PLpgSQL_stmt_close
 
struct  PLpgSQL_stmt_exit
 
struct  PLpgSQL_stmt_return
 
struct  PLpgSQL_stmt_return_next
 
struct  PLpgSQL_stmt_return_query
 
struct  PLpgSQL_stmt_raise
 
struct  PLpgSQL_raise_option
 
struct  PLpgSQL_stmt_assert
 
struct  PLpgSQL_stmt_execsql
 
struct  PLpgSQL_stmt_dynexecute
 
struct  PLpgSQL_func_hashkey
 
struct  PLpgSQL_function
 
struct  PLpgSQL_execstate
 
struct  PLpgSQL_plugin
 
struct  PLword
 
struct  PLcword
 
struct  PLwdatum
 

Macros

#define TEXTDOMAIN   PG_TEXTDOMAIN("plpgsql")
 
#define _(x)   dgettext(TEXTDOMAIN, x)
 
#define PLPGSQL_XCHECK_NONE   0
 
#define PLPGSQL_XCHECK_SHADOWVAR   (1 << 1)
 
#define PLPGSQL_XCHECK_TOOMANYROWS   (1 << 2)
 
#define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT   (1 << 3)
 
#define PLPGSQL_XCHECK_ALL   ((int) ~0)
 

Typedefs

typedef enum PLpgSQL_nsitem_type PLpgSQL_nsitem_type
 
typedef enum PLpgSQL_label_type PLpgSQL_label_type
 
typedef enum PLpgSQL_datum_type PLpgSQL_datum_type
 
typedef enum PLpgSQL_promise_type PLpgSQL_promise_type
 
typedef enum PLpgSQL_type_type PLpgSQL_type_type
 
typedef enum PLpgSQL_stmt_type PLpgSQL_stmt_type
 
typedef enum PLpgSQL_getdiag_kind PLpgSQL_getdiag_kind
 
typedef enum PLpgSQL_raise_option_type PLpgSQL_raise_option_type
 
typedef enum PLpgSQL_resolve_option PLpgSQL_resolve_option
 
typedef struct PLpgSQL_type PLpgSQL_type
 
typedef struct PLpgSQL_expr PLpgSQL_expr
 
typedef struct PLpgSQL_datum PLpgSQL_datum
 
typedef struct PLpgSQL_variable PLpgSQL_variable
 
typedef struct PLpgSQL_var PLpgSQL_var
 
typedef struct PLpgSQL_row PLpgSQL_row
 
typedef struct PLpgSQL_rec PLpgSQL_rec
 
typedef struct PLpgSQL_recfield PLpgSQL_recfield
 
typedef struct PLpgSQL_nsitem PLpgSQL_nsitem
 
typedef struct PLpgSQL_stmt PLpgSQL_stmt
 
typedef struct PLpgSQL_condition PLpgSQL_condition
 
typedef struct PLpgSQL_exception_block PLpgSQL_exception_block
 
typedef struct PLpgSQL_exception PLpgSQL_exception
 
typedef struct PLpgSQL_stmt_block PLpgSQL_stmt_block
 
typedef struct PLpgSQL_stmt_assign PLpgSQL_stmt_assign
 
typedef struct PLpgSQL_stmt_perform PLpgSQL_stmt_perform
 
typedef struct PLpgSQL_stmt_call PLpgSQL_stmt_call
 
typedef struct PLpgSQL_stmt_commit PLpgSQL_stmt_commit
 
typedef struct PLpgSQL_stmt_rollback PLpgSQL_stmt_rollback
 
typedef struct PLpgSQL_diag_item PLpgSQL_diag_item
 
typedef struct PLpgSQL_stmt_getdiag PLpgSQL_stmt_getdiag
 
typedef struct PLpgSQL_stmt_if PLpgSQL_stmt_if
 
typedef struct PLpgSQL_if_elsif PLpgSQL_if_elsif
 
typedef struct PLpgSQL_stmt_case PLpgSQL_stmt_case
 
typedef struct PLpgSQL_case_when PLpgSQL_case_when
 
typedef struct PLpgSQL_stmt_loop PLpgSQL_stmt_loop
 
typedef struct PLpgSQL_stmt_while PLpgSQL_stmt_while
 
typedef struct PLpgSQL_stmt_fori PLpgSQL_stmt_fori
 
typedef struct PLpgSQL_stmt_forq PLpgSQL_stmt_forq
 
typedef struct PLpgSQL_stmt_fors PLpgSQL_stmt_fors
 
typedef struct PLpgSQL_stmt_forc PLpgSQL_stmt_forc
 
typedef struct PLpgSQL_stmt_dynfors PLpgSQL_stmt_dynfors
 
typedef struct PLpgSQL_stmt_foreach_a PLpgSQL_stmt_foreach_a
 
typedef struct PLpgSQL_stmt_open PLpgSQL_stmt_open
 
typedef struct PLpgSQL_stmt_fetch PLpgSQL_stmt_fetch
 
typedef struct PLpgSQL_stmt_close PLpgSQL_stmt_close
 
typedef struct PLpgSQL_stmt_exit PLpgSQL_stmt_exit
 
typedef struct PLpgSQL_stmt_return PLpgSQL_stmt_return
 
typedef struct PLpgSQL_stmt_return_next PLpgSQL_stmt_return_next
 
typedef struct PLpgSQL_stmt_return_query PLpgSQL_stmt_return_query
 
typedef struct PLpgSQL_stmt_raise PLpgSQL_stmt_raise
 
typedef struct PLpgSQL_raise_option PLpgSQL_raise_option
 
typedef struct PLpgSQL_stmt_assert PLpgSQL_stmt_assert
 
typedef struct PLpgSQL_stmt_execsql PLpgSQL_stmt_execsql
 
typedef struct PLpgSQL_stmt_dynexecute PLpgSQL_stmt_dynexecute
 
typedef struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
 
typedef enum PLpgSQL_trigtype PLpgSQL_trigtype
 
typedef struct PLpgSQL_function PLpgSQL_function
 
typedef struct PLpgSQL_execstate PLpgSQL_execstate
 
typedef struct PLpgSQL_plugin PLpgSQL_plugin
 
typedef struct PLword PLword
 
typedef struct PLcword PLcword
 
typedef struct PLwdatum PLwdatum
 

Enumerations

enum  PLpgSQL_nsitem_type { PLPGSQL_NSTYPE_LABEL , PLPGSQL_NSTYPE_VAR , PLPGSQL_NSTYPE_REC }
 
enum  PLpgSQL_label_type { PLPGSQL_LABEL_BLOCK , PLPGSQL_LABEL_LOOP , PLPGSQL_LABEL_OTHER }
 
enum  PLpgSQL_datum_type {
  PLPGSQL_DTYPE_VAR , PLPGSQL_DTYPE_ROW , PLPGSQL_DTYPE_REC , PLPGSQL_DTYPE_RECFIELD ,
  PLPGSQL_DTYPE_PROMISE
}
 
enum  PLpgSQL_promise_type {
  PLPGSQL_PROMISE_NONE = 0 , PLPGSQL_PROMISE_TG_NAME , PLPGSQL_PROMISE_TG_WHEN , PLPGSQL_PROMISE_TG_LEVEL ,
  PLPGSQL_PROMISE_TG_OP , PLPGSQL_PROMISE_TG_RELID , PLPGSQL_PROMISE_TG_TABLE_NAME , PLPGSQL_PROMISE_TG_TABLE_SCHEMA ,
  PLPGSQL_PROMISE_TG_NARGS , PLPGSQL_PROMISE_TG_ARGV , PLPGSQL_PROMISE_TG_EVENT , PLPGSQL_PROMISE_TG_TAG
}
 
enum  PLpgSQL_type_type { PLPGSQL_TTYPE_SCALAR , PLPGSQL_TTYPE_REC , PLPGSQL_TTYPE_PSEUDO }
 
enum  PLpgSQL_stmt_type {
  PLPGSQL_STMT_BLOCK , PLPGSQL_STMT_ASSIGN , PLPGSQL_STMT_IF , PLPGSQL_STMT_CASE ,
  PLPGSQL_STMT_LOOP , PLPGSQL_STMT_WHILE , PLPGSQL_STMT_FORI , PLPGSQL_STMT_FORS ,
  PLPGSQL_STMT_FORC , PLPGSQL_STMT_FOREACH_A , PLPGSQL_STMT_EXIT , PLPGSQL_STMT_RETURN ,
  PLPGSQL_STMT_RETURN_NEXT , PLPGSQL_STMT_RETURN_QUERY , PLPGSQL_STMT_RAISE , PLPGSQL_STMT_ASSERT ,
  PLPGSQL_STMT_EXECSQL , PLPGSQL_STMT_DYNEXECUTE , PLPGSQL_STMT_DYNFORS , PLPGSQL_STMT_GETDIAG ,
  PLPGSQL_STMT_OPEN , PLPGSQL_STMT_FETCH , PLPGSQL_STMT_CLOSE , PLPGSQL_STMT_PERFORM ,
  PLPGSQL_STMT_CALL , PLPGSQL_STMT_COMMIT , PLPGSQL_STMT_ROLLBACK
}
 
enum  { PLPGSQL_RC_OK , PLPGSQL_RC_EXIT , PLPGSQL_RC_RETURN , PLPGSQL_RC_CONTINUE }
 
enum  PLpgSQL_getdiag_kind {
  PLPGSQL_GETDIAG_ROW_COUNT , PLPGSQL_GETDIAG_CONTEXT , PLPGSQL_GETDIAG_ERROR_CONTEXT , PLPGSQL_GETDIAG_ERROR_DETAIL ,
  PLPGSQL_GETDIAG_ERROR_HINT , PLPGSQL_GETDIAG_RETURNED_SQLSTATE , PLPGSQL_GETDIAG_COLUMN_NAME , PLPGSQL_GETDIAG_CONSTRAINT_NAME ,
  PLPGSQL_GETDIAG_DATATYPE_NAME , PLPGSQL_GETDIAG_MESSAGE_TEXT , PLPGSQL_GETDIAG_TABLE_NAME , PLPGSQL_GETDIAG_SCHEMA_NAME
}
 
enum  PLpgSQL_raise_option_type {
  PLPGSQL_RAISEOPTION_ERRCODE , PLPGSQL_RAISEOPTION_MESSAGE , PLPGSQL_RAISEOPTION_DETAIL , PLPGSQL_RAISEOPTION_HINT ,
  PLPGSQL_RAISEOPTION_COLUMN , PLPGSQL_RAISEOPTION_CONSTRAINT , PLPGSQL_RAISEOPTION_DATATYPE , PLPGSQL_RAISEOPTION_TABLE ,
  PLPGSQL_RAISEOPTION_SCHEMA
}
 
enum  PLpgSQL_resolve_option { PLPGSQL_RESOLVE_ERROR , PLPGSQL_RESOLVE_VARIABLE , PLPGSQL_RESOLVE_COLUMN }
 
enum  PLpgSQL_trigtype { PLPGSQL_DML_TRIGGER , PLPGSQL_EVENT_TRIGGER , PLPGSQL_NOT_TRIGGER }
 
enum  IdentifierLookup { IDENTIFIER_LOOKUP_NORMAL , IDENTIFIER_LOOKUP_DECLARE , IDENTIFIER_LOOKUP_EXPR }
 

Functions

PGDLLEXPORT PLpgSQL_functionplpgsql_compile (FunctionCallInfo fcinfo, bool forValidator)
 
PLpgSQL_functionplpgsql_compile_inline (char *proc_source)
 
PGDLLEXPORT void plpgsql_parser_setup (struct ParseState *pstate, PLpgSQL_expr *expr)
 
bool plpgsql_parse_word (char *word1, const char *yytxt, bool lookup, PLwdatum *wdatum, PLword *word)
 
bool plpgsql_parse_dblword (char *word1, char *word2, PLwdatum *wdatum, PLcword *cword)
 
bool plpgsql_parse_tripword (char *word1, char *word2, char *word3, PLwdatum *wdatum, PLcword *cword)
 
PLpgSQL_typeplpgsql_parse_wordtype (char *ident)
 
PLpgSQL_typeplpgsql_parse_cwordtype (List *idents)
 
PLpgSQL_typeplpgsql_parse_wordrowtype (char *ident)
 
PLpgSQL_typeplpgsql_parse_cwordrowtype (List *idents)
 
PGDLLEXPORT PLpgSQL_typeplpgsql_build_datatype (Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
 
PLpgSQL_variableplpgsql_build_variable (const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
 
PLpgSQL_recplpgsql_build_record (const char *refname, int lineno, PLpgSQL_type *dtype, Oid rectypeid, bool add2namespace)
 
PLpgSQL_recfieldplpgsql_build_recfield (PLpgSQL_rec *rec, const char *fldname)
 
PGDLLEXPORT int plpgsql_recognize_err_condition (const char *condname, bool allow_sqlstate)
 
PLpgSQL_conditionplpgsql_parse_err_condition (char *condname)
 
void plpgsql_adddatum (PLpgSQL_datum *newdatum)
 
int plpgsql_add_initdatums (int **varnos)
 
void plpgsql_HashTableInit (void)
 
Datum plpgsql_exec_function (PLpgSQL_function *func, FunctionCallInfo fcinfo, EState *simple_eval_estate, ResourceOwner simple_eval_resowner, ResourceOwner procedure_resowner, bool atomic)
 
HeapTuple plpgsql_exec_trigger (PLpgSQL_function *func, TriggerData *trigdata)
 
void plpgsql_exec_event_trigger (PLpgSQL_function *func, EventTriggerData *trigdata)
 
void plpgsql_xact_cb (XactEvent event, void *arg)
 
void plpgsql_subxact_cb (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
 
PGDLLEXPORT Oid plpgsql_exec_get_datum_type (PLpgSQL_execstate *estate, PLpgSQL_datum *datum)
 
void plpgsql_exec_get_datum_type_info (PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeId, int32 *typMod, Oid *collation)
 
void plpgsql_ns_init (void)
 
void plpgsql_ns_push (const char *label, PLpgSQL_label_type label_type)
 
void plpgsql_ns_pop (void)
 
PLpgSQL_nsitemplpgsql_ns_top (void)
 
void plpgsql_ns_additem (PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
 
PGDLLEXPORT PLpgSQL_nsitemplpgsql_ns_lookup (PLpgSQL_nsitem *ns_cur, bool localmode, const char *name1, const char *name2, const char *name3, int *names_used)
 
PLpgSQL_nsitemplpgsql_ns_lookup_label (PLpgSQL_nsitem *ns_cur, const char *name)
 
PLpgSQL_nsitemplpgsql_ns_find_nearest_loop (PLpgSQL_nsitem *ns_cur)
 
PGDLLEXPORT const char * plpgsql_stmt_typename (PLpgSQL_stmt *stmt)
 
const char * plpgsql_getdiag_kindname (PLpgSQL_getdiag_kind kind)
 
void plpgsql_free_function_memory (PLpgSQL_function *func)
 
void plpgsql_dumptree (PLpgSQL_function *func)
 
int plpgsql_base_yylex (void)
 
int plpgsql_yylex (void)
 
void plpgsql_push_back_token (int token)
 
bool plpgsql_token_is_unreserved_keyword (int token)
 
void plpgsql_append_source_text (StringInfo buf, int startlocation, int endlocation)
 
int plpgsql_peek (void)
 
void plpgsql_peek2 (int *tok1_p, int *tok2_p, int *tok1_loc, int *tok2_loc)
 
int plpgsql_scanner_errposition (int location)
 
void plpgsql_yyerror (const char *message) pg_attribute_noreturn()
 
int plpgsql_location_to_lineno (int location)
 
int plpgsql_latest_lineno (void)
 
void plpgsql_scanner_init (const char *str)
 
void plpgsql_scanner_finish (void)
 
int plpgsql_yyparse (void)
 

Variables

IdentifierLookup plpgsql_IdentifierLookup
 
int plpgsql_variable_conflict
 
bool plpgsql_print_strict_params
 
bool plpgsql_check_asserts
 
int plpgsql_extra_warnings
 
int plpgsql_extra_errors
 
bool plpgsql_check_syntax
 
bool plpgsql_DumpExecTree
 
PLpgSQL_stmt_blockplpgsql_parse_result
 
int plpgsql_nDatums
 
PLpgSQL_datum ** plpgsql_Datums
 
char * plpgsql_error_funcname
 
PLpgSQL_functionplpgsql_curr_compile
 
MemoryContext plpgsql_compile_tmp_cxt
 
PLpgSQL_plugin ** plpgsql_plugin_ptr
 

Macro Definition Documentation

◆ _

#define _ (   x)    dgettext(TEXTDOMAIN, x)

Definition at line 36 of file plpgsql.h.

◆ PLPGSQL_XCHECK_ALL

#define PLPGSQL_XCHECK_ALL   ((int) ~0)

Definition at line 1207 of file plpgsql.h.

◆ PLPGSQL_XCHECK_NONE

#define PLPGSQL_XCHECK_NONE   0

Definition at line 1203 of file plpgsql.h.

◆ PLPGSQL_XCHECK_SHADOWVAR

#define PLPGSQL_XCHECK_SHADOWVAR   (1 << 1)

Definition at line 1204 of file plpgsql.h.

◆ PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT

#define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT   (1 << 3)

Definition at line 1206 of file plpgsql.h.

◆ PLPGSQL_XCHECK_TOOMANYROWS

#define PLPGSQL_XCHECK_TOOMANYROWS   (1 << 2)

Definition at line 1205 of file plpgsql.h.

◆ TEXTDOMAIN

#define TEXTDOMAIN   PG_TEXTDOMAIN("plpgsql")

Definition at line 33 of file plpgsql.h.

Typedef Documentation

◆ PLcword

typedef struct PLcword PLcword

◆ PLpgSQL_case_when

◆ PLpgSQL_condition

◆ PLpgSQL_datum

typedef struct PLpgSQL_datum PLpgSQL_datum

◆ PLpgSQL_datum_type

◆ PLpgSQL_diag_item

◆ PLpgSQL_exception

◆ PLpgSQL_exception_block

◆ PLpgSQL_execstate

◆ PLpgSQL_expr

typedef struct PLpgSQL_expr PLpgSQL_expr

◆ PLpgSQL_func_hashkey

◆ PLpgSQL_function

◆ PLpgSQL_getdiag_kind

◆ PLpgSQL_if_elsif

◆ PLpgSQL_label_type

◆ PLpgSQL_nsitem

◆ PLpgSQL_nsitem_type

◆ PLpgSQL_plugin

◆ PLpgSQL_promise_type

◆ PLpgSQL_raise_option

◆ PLpgSQL_raise_option_type

◆ PLpgSQL_rec

typedef struct PLpgSQL_rec PLpgSQL_rec

◆ PLpgSQL_recfield

◆ PLpgSQL_resolve_option

◆ PLpgSQL_row

typedef struct PLpgSQL_row PLpgSQL_row

◆ PLpgSQL_stmt

typedef struct PLpgSQL_stmt PLpgSQL_stmt

◆ PLpgSQL_stmt_assert

◆ PLpgSQL_stmt_assign

◆ PLpgSQL_stmt_block

◆ PLpgSQL_stmt_call

◆ PLpgSQL_stmt_case

◆ PLpgSQL_stmt_close

◆ PLpgSQL_stmt_commit

◆ PLpgSQL_stmt_dynexecute

◆ PLpgSQL_stmt_dynfors

◆ PLpgSQL_stmt_execsql

◆ PLpgSQL_stmt_exit

◆ PLpgSQL_stmt_fetch

◆ PLpgSQL_stmt_forc

◆ PLpgSQL_stmt_foreach_a

◆ PLpgSQL_stmt_fori

◆ PLpgSQL_stmt_forq

◆ PLpgSQL_stmt_fors

◆ PLpgSQL_stmt_getdiag

◆ PLpgSQL_stmt_if

◆ PLpgSQL_stmt_loop

◆ PLpgSQL_stmt_open

◆ PLpgSQL_stmt_perform

◆ PLpgSQL_stmt_raise

◆ PLpgSQL_stmt_return

◆ PLpgSQL_stmt_return_next

◆ PLpgSQL_stmt_return_query

◆ PLpgSQL_stmt_rollback

◆ PLpgSQL_stmt_type

◆ PLpgSQL_stmt_while

◆ PLpgSQL_trigtype

◆ PLpgSQL_type

typedef struct PLpgSQL_type PLpgSQL_type

◆ PLpgSQL_type_type

◆ PLpgSQL_var

typedef struct PLpgSQL_var PLpgSQL_var

◆ PLpgSQL_variable

◆ PLwdatum

typedef struct PLwdatum PLwdatum

◆ PLword

typedef struct PLword PLword

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PLPGSQL_RC_OK 
PLPGSQL_RC_EXIT 
PLPGSQL_RC_RETURN 
PLPGSQL_RC_CONTINUE 

Definition at line 136 of file plpgsql.h.

137 {
142 };
@ PLPGSQL_RC_RETURN
Definition: plpgsql.h:140
@ PLPGSQL_RC_EXIT
Definition: plpgsql.h:139
@ PLPGSQL_RC_OK
Definition: plpgsql.h:138
@ PLPGSQL_RC_CONTINUE
Definition: plpgsql.h:141

◆ IdentifierLookup

Enumerator
IDENTIFIER_LOOKUP_NORMAL 
IDENTIFIER_LOOKUP_DECLARE 
IDENTIFIER_LOOKUP_EXPR 

Definition at line 1187 of file plpgsql.h.

1188 {
1189  IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
1190  IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
1191  IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
IdentifierLookup
Definition: plpgsql.h:1188
@ IDENTIFIER_LOOKUP_DECLARE
Definition: plpgsql.h:1190
@ IDENTIFIER_LOOKUP_NORMAL
Definition: plpgsql.h:1189
@ IDENTIFIER_LOOKUP_EXPR
Definition: plpgsql.h:1191

◆ PLpgSQL_datum_type

Enumerator
PLPGSQL_DTYPE_VAR 
PLPGSQL_DTYPE_ROW 
PLPGSQL_DTYPE_REC 
PLPGSQL_DTYPE_RECFIELD 
PLPGSQL_DTYPE_PROMISE 

Definition at line 61 of file plpgsql.h.

62 {
PLpgSQL_datum_type
Definition: plpgsql.h:62
@ PLPGSQL_DTYPE_ROW
Definition: plpgsql.h:64
@ PLPGSQL_DTYPE_PROMISE
Definition: plpgsql.h:67
@ PLPGSQL_DTYPE_RECFIELD
Definition: plpgsql.h:66
@ PLPGSQL_DTYPE_REC
Definition: plpgsql.h:65
@ PLPGSQL_DTYPE_VAR
Definition: plpgsql.h:63

◆ PLpgSQL_getdiag_kind

Enumerator
PLPGSQL_GETDIAG_ROW_COUNT 
PLPGSQL_GETDIAG_CONTEXT 
PLPGSQL_GETDIAG_ERROR_CONTEXT 
PLPGSQL_GETDIAG_ERROR_DETAIL 
PLPGSQL_GETDIAG_ERROR_HINT 
PLPGSQL_GETDIAG_RETURNED_SQLSTATE 
PLPGSQL_GETDIAG_COLUMN_NAME 
PLPGSQL_GETDIAG_CONSTRAINT_NAME 
PLPGSQL_GETDIAG_DATATYPE_NAME 
PLPGSQL_GETDIAG_MESSAGE_TEXT 
PLPGSQL_GETDIAG_TABLE_NAME 
PLPGSQL_GETDIAG_SCHEMA_NAME 

Definition at line 147 of file plpgsql.h.

148 {
PLpgSQL_getdiag_kind
Definition: plpgsql.h:148
@ PLPGSQL_GETDIAG_ERROR_DETAIL
Definition: plpgsql.h:152
@ PLPGSQL_GETDIAG_SCHEMA_NAME
Definition: plpgsql.h:160
@ PLPGSQL_GETDIAG_MESSAGE_TEXT
Definition: plpgsql.h:158
@ PLPGSQL_GETDIAG_DATATYPE_NAME
Definition: plpgsql.h:157
@ PLPGSQL_GETDIAG_TABLE_NAME
Definition: plpgsql.h:159
@ PLPGSQL_GETDIAG_CONSTRAINT_NAME
Definition: plpgsql.h:156
@ PLPGSQL_GETDIAG_COLUMN_NAME
Definition: plpgsql.h:155
@ PLPGSQL_GETDIAG_ROW_COUNT
Definition: plpgsql.h:149
@ PLPGSQL_GETDIAG_RETURNED_SQLSTATE
Definition: plpgsql.h:154
@ PLPGSQL_GETDIAG_CONTEXT
Definition: plpgsql.h:150
@ PLPGSQL_GETDIAG_ERROR_HINT
Definition: plpgsql.h:153
@ PLPGSQL_GETDIAG_ERROR_CONTEXT
Definition: plpgsql.h:151

◆ PLpgSQL_label_type

Enumerator
PLPGSQL_LABEL_BLOCK 
PLPGSQL_LABEL_LOOP 
PLPGSQL_LABEL_OTHER 

Definition at line 51 of file plpgsql.h.

52 {
53  PLPGSQL_LABEL_BLOCK, /* DECLARE/BEGIN block */
54  PLPGSQL_LABEL_LOOP, /* looping construct */
55  PLPGSQL_LABEL_OTHER /* anything else */
PLpgSQL_label_type
Definition: plpgsql.h:52
@ PLPGSQL_LABEL_LOOP
Definition: plpgsql.h:54
@ PLPGSQL_LABEL_OTHER
Definition: plpgsql.h:55
@ PLPGSQL_LABEL_BLOCK
Definition: plpgsql.h:53

◆ PLpgSQL_nsitem_type

Enumerator
PLPGSQL_NSTYPE_LABEL 
PLPGSQL_NSTYPE_VAR 
PLPGSQL_NSTYPE_REC 

Definition at line 41 of file plpgsql.h.

42 {
43  PLPGSQL_NSTYPE_LABEL, /* block label */
44  PLPGSQL_NSTYPE_VAR, /* scalar variable */
45  PLPGSQL_NSTYPE_REC /* composite variable */
PLpgSQL_nsitem_type
Definition: plpgsql.h:42
@ PLPGSQL_NSTYPE_VAR
Definition: plpgsql.h:44
@ PLPGSQL_NSTYPE_REC
Definition: plpgsql.h:45
@ PLPGSQL_NSTYPE_LABEL
Definition: plpgsql.h:43

◆ PLpgSQL_promise_type

Enumerator
PLPGSQL_PROMISE_NONE 
PLPGSQL_PROMISE_TG_NAME 
PLPGSQL_PROMISE_TG_WHEN 
PLPGSQL_PROMISE_TG_LEVEL 
PLPGSQL_PROMISE_TG_OP 
PLPGSQL_PROMISE_TG_RELID 
PLPGSQL_PROMISE_TG_TABLE_NAME 
PLPGSQL_PROMISE_TG_TABLE_SCHEMA 
PLPGSQL_PROMISE_TG_NARGS 
PLPGSQL_PROMISE_TG_ARGV 
PLPGSQL_PROMISE_TG_EVENT 
PLPGSQL_PROMISE_TG_TAG 

Definition at line 73 of file plpgsql.h.

74 {
75  PLPGSQL_PROMISE_NONE = 0, /* not a promise, or promise satisfied */
PLpgSQL_promise_type
Definition: plpgsql.h:74
@ PLPGSQL_PROMISE_TG_RELID
Definition: plpgsql.h:80
@ PLPGSQL_PROMISE_NONE
Definition: plpgsql.h:75
@ PLPGSQL_PROMISE_TG_WHEN
Definition: plpgsql.h:77
@ PLPGSQL_PROMISE_TG_ARGV
Definition: plpgsql.h:84
@ PLPGSQL_PROMISE_TG_TABLE_SCHEMA
Definition: plpgsql.h:82
@ PLPGSQL_PROMISE_TG_EVENT
Definition: plpgsql.h:85
@ PLPGSQL_PROMISE_TG_TABLE_NAME
Definition: plpgsql.h:81
@ PLPGSQL_PROMISE_TG_TAG
Definition: plpgsql.h:86
@ PLPGSQL_PROMISE_TG_OP
Definition: plpgsql.h:79
@ PLPGSQL_PROMISE_TG_LEVEL
Definition: plpgsql.h:78
@ PLPGSQL_PROMISE_TG_NARGS
Definition: plpgsql.h:83
@ PLPGSQL_PROMISE_TG_NAME
Definition: plpgsql.h:76

◆ PLpgSQL_raise_option_type

Enumerator
PLPGSQL_RAISEOPTION_ERRCODE 
PLPGSQL_RAISEOPTION_MESSAGE 
PLPGSQL_RAISEOPTION_DETAIL 
PLPGSQL_RAISEOPTION_HINT 
PLPGSQL_RAISEOPTION_COLUMN 
PLPGSQL_RAISEOPTION_CONSTRAINT 
PLPGSQL_RAISEOPTION_DATATYPE 
PLPGSQL_RAISEOPTION_TABLE 
PLPGSQL_RAISEOPTION_SCHEMA 

Definition at line 166 of file plpgsql.h.

167 {
PLpgSQL_raise_option_type
Definition: plpgsql.h:167
@ PLPGSQL_RAISEOPTION_COLUMN
Definition: plpgsql.h:172
@ PLPGSQL_RAISEOPTION_TABLE
Definition: plpgsql.h:175
@ PLPGSQL_RAISEOPTION_SCHEMA
Definition: plpgsql.h:176
@ PLPGSQL_RAISEOPTION_CONSTRAINT
Definition: plpgsql.h:173
@ PLPGSQL_RAISEOPTION_DETAIL
Definition: plpgsql.h:170
@ PLPGSQL_RAISEOPTION_MESSAGE
Definition: plpgsql.h:169
@ PLPGSQL_RAISEOPTION_HINT
Definition: plpgsql.h:171
@ PLPGSQL_RAISEOPTION_ERRCODE
Definition: plpgsql.h:168
@ PLPGSQL_RAISEOPTION_DATATYPE
Definition: plpgsql.h:174

◆ PLpgSQL_resolve_option

Enumerator
PLPGSQL_RESOLVE_ERROR 
PLPGSQL_RESOLVE_VARIABLE 
PLPGSQL_RESOLVE_COLUMN 

Definition at line 182 of file plpgsql.h.

183 {
184  PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
185  PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
186  PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */
PLpgSQL_resolve_option
Definition: plpgsql.h:183
@ PLPGSQL_RESOLVE_COLUMN
Definition: plpgsql.h:186
@ PLPGSQL_RESOLVE_ERROR
Definition: plpgsql.h:184
@ PLPGSQL_RESOLVE_VARIABLE
Definition: plpgsql.h:185

◆ PLpgSQL_stmt_type

Enumerator
PLPGSQL_STMT_BLOCK 
PLPGSQL_STMT_ASSIGN 
PLPGSQL_STMT_IF 
PLPGSQL_STMT_CASE 
PLPGSQL_STMT_LOOP 
PLPGSQL_STMT_WHILE 
PLPGSQL_STMT_FORI 
PLPGSQL_STMT_FORS 
PLPGSQL_STMT_FORC 
PLPGSQL_STMT_FOREACH_A 
PLPGSQL_STMT_EXIT 
PLPGSQL_STMT_RETURN 
PLPGSQL_STMT_RETURN_NEXT 
PLPGSQL_STMT_RETURN_QUERY 
PLPGSQL_STMT_RAISE 
PLPGSQL_STMT_ASSERT 
PLPGSQL_STMT_EXECSQL 
PLPGSQL_STMT_DYNEXECUTE 
PLPGSQL_STMT_DYNFORS 
PLPGSQL_STMT_GETDIAG 
PLPGSQL_STMT_OPEN 
PLPGSQL_STMT_FETCH 
PLPGSQL_STMT_CLOSE 
PLPGSQL_STMT_PERFORM 
PLPGSQL_STMT_CALL 
PLPGSQL_STMT_COMMIT 
PLPGSQL_STMT_ROLLBACK 

Definition at line 102 of file plpgsql.h.

103 {
PLpgSQL_stmt_type
Definition: plpgsql.h:103
@ PLPGSQL_STMT_DYNFORS
Definition: plpgsql.h:122
@ PLPGSQL_STMT_FORI
Definition: plpgsql.h:110
@ PLPGSQL_STMT_FETCH
Definition: plpgsql.h:125
@ PLPGSQL_STMT_CASE
Definition: plpgsql.h:107
@ PLPGSQL_STMT_OPEN
Definition: plpgsql.h:124
@ PLPGSQL_STMT_ROLLBACK
Definition: plpgsql.h:130
@ PLPGSQL_STMT_COMMIT
Definition: plpgsql.h:129
@ PLPGSQL_STMT_RETURN_QUERY
Definition: plpgsql.h:117
@ PLPGSQL_STMT_RETURN
Definition: plpgsql.h:115
@ PLPGSQL_STMT_CLOSE
Definition: plpgsql.h:126
@ PLPGSQL_STMT_WHILE
Definition: plpgsql.h:109
@ PLPGSQL_STMT_BLOCK
Definition: plpgsql.h:104
@ PLPGSQL_STMT_FORS
Definition: plpgsql.h:111
@ PLPGSQL_STMT_FORC
Definition: plpgsql.h:112
@ PLPGSQL_STMT_IF
Definition: plpgsql.h:106
@ PLPGSQL_STMT_PERFORM
Definition: plpgsql.h:127
@ PLPGSQL_STMT_LOOP
Definition: plpgsql.h:108
@ PLPGSQL_STMT_ASSERT
Definition: plpgsql.h:119
@ PLPGSQL_STMT_FOREACH_A
Definition: plpgsql.h:113
@ PLPGSQL_STMT_GETDIAG
Definition: plpgsql.h:123
@ PLPGSQL_STMT_RETURN_NEXT
Definition: plpgsql.h:116
@ PLPGSQL_STMT_ASSIGN
Definition: plpgsql.h:105
@ PLPGSQL_STMT_EXIT
Definition: plpgsql.h:114
@ PLPGSQL_STMT_EXECSQL
Definition: plpgsql.h:120
@ PLPGSQL_STMT_RAISE
Definition: plpgsql.h:118
@ PLPGSQL_STMT_CALL
Definition: plpgsql.h:128
@ PLPGSQL_STMT_DYNEXECUTE
Definition: plpgsql.h:121

◆ PLpgSQL_trigtype

Enumerator
PLPGSQL_DML_TRIGGER 
PLPGSQL_EVENT_TRIGGER 
PLPGSQL_NOT_TRIGGER 

Definition at line 955 of file plpgsql.h.

956 {
PLpgSQL_trigtype
Definition: plpgsql.h:956
@ PLPGSQL_DML_TRIGGER
Definition: plpgsql.h:957
@ PLPGSQL_NOT_TRIGGER
Definition: plpgsql.h:959
@ PLPGSQL_EVENT_TRIGGER
Definition: plpgsql.h:958

◆ PLpgSQL_type_type

Enumerator
PLPGSQL_TTYPE_SCALAR 
PLPGSQL_TTYPE_REC 
PLPGSQL_TTYPE_PSEUDO 

Definition at line 92 of file plpgsql.h.

93 {
94  PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
95  PLPGSQL_TTYPE_REC, /* composite types, including RECORD */
96  PLPGSQL_TTYPE_PSEUDO /* pseudotypes */
PLpgSQL_type_type
Definition: plpgsql.h:93
@ PLPGSQL_TTYPE_PSEUDO
Definition: plpgsql.h:96
@ PLPGSQL_TTYPE_REC
Definition: plpgsql.h:95
@ PLPGSQL_TTYPE_SCALAR
Definition: plpgsql.h:94

Function Documentation

◆ plpgsql_add_initdatums()

int plpgsql_add_initdatums ( int **  varnos)

Definition at line 2388 of file pl_comp.c.

2389 {
2390  int i;
2391  int n = 0;
2392 
2393  /*
2394  * The set of dtypes recognized here must match what exec_stmt_block()
2395  * cares about (re)initializing at block entry.
2396  */
2397  for (i = datums_last; i < plpgsql_nDatums; i++)
2398  {
2399  switch (plpgsql_Datums[i]->dtype)
2400  {
2401  case PLPGSQL_DTYPE_VAR:
2402  case PLPGSQL_DTYPE_REC:
2403  n++;
2404  break;
2405 
2406  default:
2407  break;
2408  }
2409  }
2410 
2411  if (varnos != NULL)
2412  {
2413  if (n > 0)
2414  {
2415  *varnos = (int *) palloc(sizeof(int) * n);
2416 
2417  n = 0;
2418  for (i = datums_last; i < plpgsql_nDatums; i++)
2419  {
2420  switch (plpgsql_Datums[i]->dtype)
2421  {
2422  case PLPGSQL_DTYPE_VAR:
2423  case PLPGSQL_DTYPE_REC:
2424  (*varnos)[n++] = plpgsql_Datums[i]->dno;
2425 
2426  default:
2427  break;
2428  }
2429  }
2430  }
2431  else
2432  *varnos = NULL;
2433  }
2434 
2436  return n;
2437 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1199
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:46
static int datums_last
Definition: pl_comp.c:47
int plpgsql_nDatums
Definition: pl_comp.c:45

References datums_last, PLpgSQL_datum::dno, i, palloc(), plpgsql_Datums, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_VAR, and plpgsql_nDatums.

◆ plpgsql_adddatum()

void plpgsql_adddatum ( PLpgSQL_datum newdatum)

Definition at line 2327 of file pl_comp.c.

2328 {
2330  {
2331  datums_alloc *= 2;
2333  }
2334 
2335  newdatum->dno = plpgsql_nDatums;
2336  plpgsql_Datums[plpgsql_nDatums++] = newdatum;
2337 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1321
static int datums_alloc
Definition: pl_comp.c:44

References datums_alloc, PLpgSQL_datum::dno, plpgsql_Datums, plpgsql_nDatums, and repalloc().

Referenced by do_compile(), plpgsql_build_recfield(), plpgsql_build_record(), and plpgsql_build_variable().

◆ plpgsql_append_source_text()

void plpgsql_append_source_text ( StringInfo  buf,
int  startlocation,
int  endlocation 
)

Definition at line 404 of file pl_scanner.c.

406 {
407  Assert(startlocation <= endlocation);
408  appendBinaryStringInfo(buf, scanorig + startlocation,
409  endlocation - startlocation);
410 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static char * buf
Definition: pg_test_fsync.c:67
static const char * scanorig
Definition: pl_scanner.c:110
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227

References appendBinaryStringInfo(), Assert(), buf, and scanorig.

◆ plpgsql_base_yylex()

int plpgsql_base_yylex ( void  )

◆ plpgsql_build_datatype()

PGDLLEXPORT PLpgSQL_type* plpgsql_build_datatype ( Oid  typeOid,
int32  typmod,
Oid  collation,
TypeName origtypname 
)

Definition at line 2085 of file pl_comp.c.

2087 {
2088  HeapTuple typeTup;
2089  PLpgSQL_type *typ;
2090 
2091  typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typeOid));
2092  if (!HeapTupleIsValid(typeTup))
2093  elog(ERROR, "cache lookup failed for type %u", typeOid);
2094 
2095  typ = build_datatype(typeTup, typmod, collation, origtypname);
2096 
2097  ReleaseSysCache(typeTup);
2098 
2099  return typ;
2100 }
#define ERROR
Definition: elog.h:35
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static PLpgSQL_type * build_datatype(HeapTuple typeTup, int32 typmod, Oid collation, TypeName *origtypname)
Definition: pl_comp.c:2107
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ TYPEOID
Definition: syscache.h:114

References build_datatype(), elog(), ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and TYPEOID.

Referenced by do_compile(), exec_stmt_case(), plpgsql_compile_inline(), plpgsql_parse_cwordrowtype(), and plpgsql_parse_wordrowtype().

◆ plpgsql_build_recfield()

PLpgSQL_recfield* plpgsql_build_recfield ( PLpgSQL_rec rec,
const char *  fldname 
)

Definition at line 2038 of file pl_comp.c.

2039 {
2040  PLpgSQL_recfield *recfield;
2041  int i;
2042 
2043  /* search for an existing datum referencing this field */
2044  i = rec->firstfield;
2045  while (i >= 0)
2046  {
2048 
2050  fld->recparentno == rec->dno);
2051  if (strcmp(fld->fieldname, fldname) == 0)
2052  return fld;
2053  i = fld->nextfield;
2054  }
2055 
2056  /* nope, so make a new one */
2057  recfield = palloc0(sizeof(PLpgSQL_recfield));
2058  recfield->dtype = PLPGSQL_DTYPE_RECFIELD;
2059  recfield->fieldname = pstrdup(fldname);
2060  recfield->recparentno = rec->dno;
2062 
2063  plpgsql_adddatum((PLpgSQL_datum *) recfield);
2064 
2065  /* now we can link it into the parent's chain */
2066  recfield->nextfield = rec->firstfield;
2067  rec->firstfield = recfield->dno;
2068 
2069  return recfield;
2070 }
char * pstrdup(const char *in)
Definition: mcxt.c:1483
void * palloc0(Size size)
Definition: mcxt.c:1230
void plpgsql_adddatum(PLpgSQL_datum *newdatum)
Definition: pl_comp.c:2327
int firstfield
Definition: plpgsql.h:408
uint64 rectupledescid
Definition: plpgsql.h:428
PLpgSQL_datum_type dtype
Definition: plpgsql.h:421
char * fieldname
Definition: plpgsql.h:425
#define INVALID_TUPLEDESC_IDENTIFIER
Definition: typcache.h:155

References Assert(), PLpgSQL_rec::dno, PLpgSQL_recfield::dno, PLpgSQL_recfield::dtype, PLpgSQL_recfield::fieldname, PLpgSQL_rec::firstfield, i, INVALID_TUPLEDESC_IDENTIFIER, PLpgSQL_recfield::nextfield, palloc0(), plpgsql_adddatum(), plpgsql_Datums, PLPGSQL_DTYPE_RECFIELD, pstrdup(), PLpgSQL_recfield::recparentno, and PLpgSQL_recfield::rectupledescid.

Referenced by plpgsql_parse_dblword(), and plpgsql_parse_tripword().

◆ plpgsql_build_record()

PLpgSQL_rec* plpgsql_build_record ( const char *  refname,
int  lineno,
PLpgSQL_type dtype,
Oid  rectypeid,
bool  add2namespace 
)

Definition at line 1944 of file pl_comp.c.

1947 {
1948  PLpgSQL_rec *rec;
1949 
1950  rec = palloc0(sizeof(PLpgSQL_rec));
1951  rec->dtype = PLPGSQL_DTYPE_REC;
1952  rec->refname = pstrdup(refname);
1953  rec->lineno = lineno;
1954  /* other fields are left as 0, might be changed by caller */
1955  rec->datatype = dtype;
1956  rec->rectypeid = rectypeid;
1957  rec->firstfield = -1;
1958  rec->erh = NULL;
1960  if (add2namespace)
1962 
1963  return rec;
1964 }
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:92
ExpandedRecordHeader * erh
Definition: plpgsql.h:413
PLpgSQL_type * datatype
Definition: plpgsql.h:405
PLpgSQL_datum_type dtype
Definition: plpgsql.h:390
Oid rectypeid
Definition: plpgsql.h:406
int lineno
Definition: plpgsql.h:393
char * refname
Definition: plpgsql.h:392

References PLpgSQL_rec::datatype, PLpgSQL_rec::dno, PLpgSQL_rec::dtype, PLpgSQL_rec::erh, PLpgSQL_rec::firstfield, PLpgSQL_rec::lineno, palloc0(), plpgsql_adddatum(), PLPGSQL_DTYPE_REC, plpgsql_ns_additem(), PLPGSQL_NSTYPE_REC, pstrdup(), PLpgSQL_rec::rectypeid, and PLpgSQL_rec::refname.

Referenced by do_compile(), and plpgsql_build_variable().

◆ plpgsql_build_variable()

PLpgSQL_variable* plpgsql_build_variable ( const char *  refname,
int  lineno,
PLpgSQL_type dtype,
bool  add2namespace 
)

Definition at line 1881 of file pl_comp.c.

1883 {
1884  PLpgSQL_variable *result;
1885 
1886  switch (dtype->ttype)
1887  {
1888  case PLPGSQL_TTYPE_SCALAR:
1889  {
1890  /* Ordinary scalar datatype */
1891  PLpgSQL_var *var;
1892 
1893  var = palloc0(sizeof(PLpgSQL_var));
1894  var->dtype = PLPGSQL_DTYPE_VAR;
1895  var->refname = pstrdup(refname);
1896  var->lineno = lineno;
1897  var->datatype = dtype;
1898  /* other fields are left as 0, might be changed by caller */
1899 
1900  /* preset to NULL */
1901  var->value = 0;
1902  var->isnull = true;
1903  var->freeval = false;
1904 
1906  if (add2namespace)
1908  var->dno,
1909  refname);
1910  result = (PLpgSQL_variable *) var;
1911  break;
1912  }
1913  case PLPGSQL_TTYPE_REC:
1914  {
1915  /* Composite type -- build a record variable */
1916  PLpgSQL_rec *rec;
1917 
1918  rec = plpgsql_build_record(refname, lineno,
1919  dtype, dtype->typoid,
1920  add2namespace);
1921  result = (PLpgSQL_variable *) rec;
1922  break;
1923  }
1924  case PLPGSQL_TTYPE_PSEUDO:
1925  ereport(ERROR,
1926  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1927  errmsg("variable \"%s\" has pseudo-type %s",
1928  refname, format_type_be(dtype->typoid))));
1929  result = NULL; /* keep compiler quiet */
1930  break;
1931  default:
1932  elog(ERROR, "unrecognized ttype: %d", dtype->ttype);
1933  result = NULL; /* keep compiler quiet */
1934  break;
1935  }
1936 
1937  return result;
1938 }
int errcode(int sqlerrcode)
Definition: elog.c:735
int errmsg(const char *fmt,...)
Definition: elog.c:946
#define ereport(elevel,...)
Definition: elog.h:145
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
PLpgSQL_rec * plpgsql_build_record(const char *refname, int lineno, PLpgSQL_type *dtype, Oid rectypeid, bool add2namespace)
Definition: pl_comp.c:1944
PLpgSQL_type_type ttype
Definition: plpgsql.h:201
Oid typoid
Definition: plpgsql.h:200
int lineno
Definition: plpgsql.h:313
PLpgSQL_datum_type dtype
Definition: plpgsql.h:310
bool freeval
Definition: plpgsql.h:334
bool isnull
Definition: plpgsql.h:333
PLpgSQL_type * datatype
Definition: plpgsql.h:319
char * refname
Definition: plpgsql.h:312
Datum value
Definition: plpgsql.h:332

References PLpgSQL_var::datatype, PLpgSQL_var::dno, PLpgSQL_var::dtype, elog(), ereport, errcode(), errmsg(), ERROR, format_type_be(), PLpgSQL_var::freeval, PLpgSQL_var::isnull, PLpgSQL_var::lineno, palloc0(), plpgsql_adddatum(), plpgsql_build_record(), PLPGSQL_DTYPE_VAR, plpgsql_ns_additem(), PLPGSQL_NSTYPE_VAR, PLPGSQL_TTYPE_PSEUDO, PLPGSQL_TTYPE_REC, PLPGSQL_TTYPE_SCALAR, pstrdup(), PLpgSQL_var::refname, PLpgSQL_type::ttype, PLpgSQL_type::typoid, and PLpgSQL_var::value.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_compile()

PGDLLEXPORT PLpgSQL_function* plpgsql_compile ( FunctionCallInfo  fcinfo,
bool  forValidator 
)

Definition at line 136 of file pl_comp.c.

137 {
138  Oid funcOid = fcinfo->flinfo->fn_oid;
139  HeapTuple procTup;
140  Form_pg_proc procStruct;
141  PLpgSQL_function *function;
142  PLpgSQL_func_hashkey hashkey;
143  bool function_valid = false;
144  bool hashkey_valid = false;
145 
146  /*
147  * Lookup the pg_proc tuple by Oid; we'll need it in any case
148  */
149  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcOid));
150  if (!HeapTupleIsValid(procTup))
151  elog(ERROR, "cache lookup failed for function %u", funcOid);
152  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
153 
154  /*
155  * See if there's already a cache entry for the current FmgrInfo. If not,
156  * try to find one in the hash table.
157  */
158  function = (PLpgSQL_function *) fcinfo->flinfo->fn_extra;
159 
160 recheck:
161  if (!function)
162  {
163  /* Compute hashkey using function signature and actual arg types */
164  compute_function_hashkey(fcinfo, procStruct, &hashkey, forValidator);
165  hashkey_valid = true;
166 
167  /* And do the lookup */
168  function = plpgsql_HashTableLookup(&hashkey);
169  }
170 
171  if (function)
172  {
173  /* We have a compiled function, but is it still valid? */
174  if (function->fn_xmin == HeapTupleHeaderGetRawXmin(procTup->t_data) &&
175  ItemPointerEquals(&function->fn_tid, &procTup->t_self))
176  function_valid = true;
177  else
178  {
179  /*
180  * Nope, so remove it from hashtable and try to drop associated
181  * storage (if not done already).
182  */
183  delete_function(function);
184 
185  /*
186  * If the function isn't in active use then we can overwrite the
187  * func struct with new data, allowing any other existing fn_extra
188  * pointers to make use of the new definition on their next use.
189  * If it is in use then just leave it alone and make a new one.
190  * (The active invocations will run to completion using the
191  * previous definition, and then the cache entry will just be
192  * leaked; doesn't seem worth adding code to clean it up, given
193  * what a corner case this is.)
194  *
195  * If we found the function struct via fn_extra then it's possible
196  * a replacement has already been made, so go back and recheck the
197  * hashtable.
198  */
199  if (function->use_count != 0)
200  {
201  function = NULL;
202  if (!hashkey_valid)
203  goto recheck;
204  }
205  }
206  }
207 
208  /*
209  * If the function wasn't found or was out-of-date, we have to compile it
210  */
211  if (!function_valid)
212  {
213  /*
214  * Calculate hashkey if we didn't already; we'll need it to store the
215  * completed function.
216  */
217  if (!hashkey_valid)
218  compute_function_hashkey(fcinfo, procStruct, &hashkey,
219  forValidator);
220 
221  /*
222  * Do the hard part.
223  */
224  function = do_compile(fcinfo, procTup, function,
225  &hashkey, forValidator);
226  }
227 
228  ReleaseSysCache(procTup);
229 
230  /*
231  * Save pointer in FmgrInfo to avoid search on subsequent calls
232  */
233  fcinfo->flinfo->fn_extra = (void *) function;
234 
235  /*
236  * Finally return the compiled function
237  */
238  return function;
239 }
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:303
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
on_exit_nicely_callback function
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
static void compute_function_hashkey(FunctionCallInfo fcinfo, Form_pg_proc procStruct, PLpgSQL_func_hashkey *hashkey, bool forValidator)
Definition: pl_comp.c:2446
static PLpgSQL_function * plpgsql_HashTableLookup(PLpgSQL_func_hashkey *func_key)
Definition: pl_comp.c:2625
static PLpgSQL_function * do_compile(FunctionCallInfo fcinfo, HeapTuple procTup, PLpgSQL_function *function, PLpgSQL_func_hashkey *hashkey, bool forValidator)
Definition: pl_comp.c:264
static void delete_function(PLpgSQL_function *func)
Definition: pl_comp.c:2597
unsigned int Oid
Definition: postgres_ext.h:31
void * fn_extra
Definition: fmgr.h:64
Oid fn_oid
Definition: fmgr.h:59
FmgrInfo * flinfo
Definition: fmgr.h:87
ItemPointerData t_self
Definition: htup.h:65
HeapTupleHeader t_data
Definition: htup.h:68
@ PROCOID
Definition: syscache.h:79

References compute_function_hashkey(), delete_function(), do_compile(), elog(), ERROR, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_extra, FmgrInfo::fn_oid, function, GETSTRUCT, HeapTupleHeaderGetRawXmin, HeapTupleIsValid, if(), ItemPointerEquals(), ObjectIdGetDatum(), plpgsql_HashTableLookup(), PROCOID, ReleaseSysCache(), SearchSysCache1(), HeapTupleData::t_data, and HeapTupleData::t_self.

Referenced by plpgsql_call_handler(), and plpgsql_validator().

◆ plpgsql_compile_inline()

PLpgSQL_function* plpgsql_compile_inline ( char *  proc_source)

Definition at line 847 of file pl_comp.c.

848 {
849  char *func_name = "inline_code_block";
850  PLpgSQL_function *function;
851  ErrorContextCallback plerrcontext;
852  PLpgSQL_variable *var;
853  int parse_rc;
854  MemoryContext func_cxt;
855 
856  /*
857  * Setup the scanner input and error info. We assume that this function
858  * cannot be invoked recursively, so there's no need to save and restore
859  * the static variables used here.
860  */
861  plpgsql_scanner_init(proc_source);
862 
863  plpgsql_error_funcname = func_name;
864 
865  /*
866  * Setup error traceback support for ereport()
867  */
869  plerrcontext.arg = proc_source;
870  plerrcontext.previous = error_context_stack;
871  error_context_stack = &plerrcontext;
872 
873  /* Do extra syntax checking if check_function_bodies is on */
875 
876  /* Function struct does not live past current statement */
877  function = (PLpgSQL_function *) palloc0(sizeof(PLpgSQL_function));
878 
879  plpgsql_curr_compile = function;
880 
881  /*
882  * All the rest of the compile-time storage (e.g. parse tree) is kept in
883  * its own memory context, so it can be reclaimed easily.
884  */
886  "PL/pgSQL inline code context",
889 
890  function->fn_signature = pstrdup(func_name);
891  function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
892  function->fn_input_collation = InvalidOid;
893  function->fn_cxt = func_cxt;
894  function->out_param_varno = -1; /* set up for no OUT param */
895  function->resolve_option = plpgsql_variable_conflict;
896  function->print_strict_params = plpgsql_print_strict_params;
897 
898  /*
899  * don't do extra validation for inline code as we don't want to add spam
900  * at runtime
901  */
902  function->extra_warnings = 0;
903  function->extra_errors = 0;
904 
905  function->nstatements = 0;
906  function->requires_procedure_resowner = false;
907 
908  plpgsql_ns_init();
910  plpgsql_DumpExecTree = false;
912 
913  /* Set up as though in a function returning VOID */
914  function->fn_rettype = VOIDOID;
915  function->fn_retset = false;
916  function->fn_retistuple = false;
917  function->fn_retisdomain = false;
918  function->fn_prokind = PROKIND_FUNCTION;
919  /* a bit of hardwired knowledge about type VOID here */
920  function->fn_retbyval = true;
921  function->fn_rettyplen = sizeof(int32);
922 
923  /*
924  * Remember if function is STABLE/IMMUTABLE. XXX would it be better to
925  * set this true inside a read-only transaction? Not clear.
926  */
927  function->fn_readonly = false;
928 
929  /*
930  * Create the magic FOUND variable.
931  */
932  var = plpgsql_build_variable("found", 0,
933  plpgsql_build_datatype(BOOLOID,
934  -1,
935  InvalidOid,
936  NULL),
937  true);
938  function->found_varno = var->dno;
939 
940  /*
941  * Now parse the function's text
942  */
943  parse_rc = plpgsql_yyparse();
944  if (parse_rc != 0)
945  elog(ERROR, "plpgsql parser returned %d", parse_rc);
946  function->action = plpgsql_parse_result;
947 
949 
950  /*
951  * If it returns VOID (always true at the moment), we allow control to
952  * fall off the end without an explicit RETURN statement.
953  */
954  if (function->fn_rettype == VOIDOID)
955  add_dummy_return(function);
956 
957  /*
958  * Complete the function's info
959  */
960  function->fn_nargs = 0;
961 
962  plpgsql_finish_datums(function);
963 
964  /*
965  * Pop the error context stack
966  */
967  error_context_stack = plerrcontext.previous;
968  plpgsql_error_funcname = NULL;
969 
970  plpgsql_check_syntax = false;
971 
974  return function;
975 }
signed int int32
Definition: c.h:430
ErrorContextCallback * error_context_stack
Definition: elog.c:94
bool check_function_bodies
Definition: guc_tables.c:476
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
static void add_dummy_return(PLpgSQL_function *function)
Definition: pl_comp.c:1036
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:56
static void plpgsql_compile_error_callback(void *arg)
Definition: pl_comp.c:984
PLpgSQL_variable * plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
Definition: pl_comp.c:1881
static void plpgsql_start_datums(void)
Definition: pl_comp.c:2310
char * plpgsql_error_funcname
Definition: pl_comp.c:49
PLpgSQL_stmt_block * plpgsql_parse_result
Definition: pl_comp.c:42
bool plpgsql_check_syntax
Definition: pl_comp.c:51
static void plpgsql_finish_datums(PLpgSQL_function *function)
Definition: pl_comp.c:2344
PLpgSQL_function * plpgsql_curr_compile
Definition: pl_comp.c:53
bool plpgsql_DumpExecTree
Definition: pl_comp.c:50
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
Definition: pl_comp.c:2085
void plpgsql_ns_init(void)
Definition: pl_funcs.c:43
void plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
Definition: pl_funcs.c:54
int plpgsql_variable_conflict
Definition: pl_handler.c:44
bool plpgsql_print_strict_params
Definition: pl_handler.c:46
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:613
void plpgsql_scanner_init(const char *str)
Definition: pl_scanner.c:586
int plpgsql_yyparse(void)
#define InvalidOid
Definition: postgres_ext.h:36
struct ErrorContextCallback * previous
Definition: elog.h:234
void(* callback)(void *arg)
Definition: elog.h:235

References add_dummy_return(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ErrorContextCallback::arg, ErrorContextCallback::callback, check_function_bodies, CurrentMemoryContext, PLpgSQL_variable::dno, elog(), ERROR, error_context_stack, function, InvalidOid, MemoryContextSwitchTo(), palloc0(), plpgsql_build_datatype(), plpgsql_build_variable(), plpgsql_check_syntax, plpgsql_compile_error_callback(), plpgsql_compile_tmp_cxt, plpgsql_curr_compile, plpgsql_DumpExecTree, plpgsql_error_funcname, plpgsql_finish_datums(), PLPGSQL_LABEL_BLOCK, PLPGSQL_NOT_TRIGGER, plpgsql_ns_init(), plpgsql_ns_push(), plpgsql_parse_result, plpgsql_print_strict_params, plpgsql_scanner_finish(), plpgsql_scanner_init(), plpgsql_start_datums(), plpgsql_variable_conflict, plpgsql_yyparse(), ErrorContextCallback::previous, and pstrdup().

Referenced by plpgsql_inline_handler().

◆ plpgsql_dumptree()

void plpgsql_dumptree ( PLpgSQL_function func)

Definition at line 1598 of file pl_funcs.c.

1599 {
1600  int i;
1601  PLpgSQL_datum *d;
1602 
1603  printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1604  func->fn_signature);
1605 
1606  printf("\nFunction's data area:\n");
1607  for (i = 0; i < func->ndatums; i++)
1608  {
1609  d = func->datums[i];
1610 
1611  printf(" entry %d: ", i);
1612  switch (d->dtype)
1613  {
1614  case PLPGSQL_DTYPE_VAR:
1615  case PLPGSQL_DTYPE_PROMISE:
1616  {
1617  PLpgSQL_var *var = (PLpgSQL_var *) d;
1618 
1619  printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1620  var->refname, var->datatype->typname,
1621  var->datatype->typoid,
1622  var->datatype->atttypmod);
1623  if (var->isconst)
1624  printf(" CONSTANT\n");
1625  if (var->notnull)
1626  printf(" NOT NULL\n");
1627  if (var->default_val != NULL)
1628  {
1629  printf(" DEFAULT ");
1630  dump_expr(var->default_val);
1631  printf("\n");
1632  }
1633  if (var->cursor_explicit_expr != NULL)
1634  {
1635  if (var->cursor_explicit_argrow >= 0)
1636  printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1637 
1638  printf(" CURSOR IS ");
1640  printf("\n");
1641  }
1642  if (var->promise != PLPGSQL_PROMISE_NONE)
1643  printf(" PROMISE %d\n",
1644  (int) var->promise);
1645  }
1646  break;
1647  case PLPGSQL_DTYPE_ROW:
1648  {
1649  PLpgSQL_row *row = (PLpgSQL_row *) d;
1650 
1651  printf("ROW %-16s fields", row->refname);
1652  for (int j = 0; j < row->nfields; j++)
1653  {
1654  printf(" %s=var %d", row->fieldnames[j],
1655  row->varnos[j]);
1656  }
1657  printf("\n");
1658  }
1659  break;
1660  case PLPGSQL_DTYPE_REC:
1661  printf("REC %-16s typoid %u\n",
1662  ((PLpgSQL_rec *) d)->refname,
1663  ((PLpgSQL_rec *) d)->rectypeid);
1664  if (((PLpgSQL_rec *) d)->isconst)
1665  printf(" CONSTANT\n");
1666  if (((PLpgSQL_rec *) d)->notnull)
1667  printf(" NOT NULL\n");
1668  if (((PLpgSQL_rec *) d)->default_val != NULL)
1669  {
1670  printf(" DEFAULT ");
1671  dump_expr(((PLpgSQL_rec *) d)->default_val);
1672  printf("\n");
1673  }
1674  break;
1676  printf("RECFIELD %-16s of REC %d\n",
1677  ((PLpgSQL_recfield *) d)->fieldname,
1678  ((PLpgSQL_recfield *) d)->recparentno);
1679  break;
1680  default:
1681  printf("??? unknown data type %d\n", d->dtype);
1682  }
1683  }
1684  printf("\nFunction's statements:\n");
1685 
1686  dump_indent = 0;
1687  printf("%3d:", func->action->lineno);
1688  dump_block(func->action);
1689  printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1690  fflush(stdout);
1691 }
int j
Definition: isn.c:74
static void const char fflush(stdout)
static int dump_indent
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1592
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:933
#define printf(...)
Definition: port.h:244
PLpgSQL_datum_type dtype
Definition: plpgsql.h:276
PLpgSQL_stmt_block * action
Definition: plpgsql.h:1006
PLpgSQL_datum ** datums
Definition: plpgsql.h:1002
char * fn_signature
Definition: plpgsql.h:967
int * varnos
Definition: plpgsql.h:382
char * refname
Definition: plpgsql.h:366
char ** fieldnames
Definition: plpgsql.h:381
int nfields
Definition: plpgsql.h:380
char * typname
Definition: plpgsql.h:199
int32 atttypmod
Definition: plpgsql.h:207
PLpgSQL_promise_type promise
Definition: plpgsql.h:341
int cursor_explicit_argrow
Definition: plpgsql.h:327
bool notnull
Definition: plpgsql.h:315
bool isconst
Definition: plpgsql.h:314
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:326
PLpgSQL_expr * default_val
Definition: plpgsql.h:316

References PLpgSQL_function::action, PLpgSQL_type::atttypmod, PLpgSQL_var::cursor_explicit_argrow, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_var::datatype, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_datum::dtype, PLpgSQL_rec::dtype, dump_block(), dump_expr(), dump_indent, fflush(), PLpgSQL_row::fieldnames, PLpgSQL_function::fn_signature, i, PLpgSQL_var::isconst, j, PLpgSQL_stmt_block::lineno, PLpgSQL_function::ndatums, PLpgSQL_row::nfields, PLpgSQL_var::notnull, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLPGSQL_PROMISE_NONE, printf, PLpgSQL_var::promise, PLpgSQL_var::refname, PLpgSQL_row::refname, generate_unaccent_rules::stdout, PLpgSQL_type::typname, PLpgSQL_type::typoid, and PLpgSQL_row::varnos.

Referenced by do_compile().

◆ plpgsql_exec_event_trigger()

void plpgsql_exec_event_trigger ( PLpgSQL_function func,
EventTriggerData trigdata 
)

Definition at line 1152 of file pl_exec.c.

1153 {
1154  PLpgSQL_execstate estate;
1155  ErrorContextCallback plerrcontext;
1156  int rc;
1157 
1158  /*
1159  * Setup the execution state
1160  */
1161  plpgsql_estate_setup(&estate, func, NULL, NULL, NULL);
1162  estate.evtrigdata = trigdata;
1163 
1164  /*
1165  * Setup error traceback support for ereport()
1166  */
1167  plerrcontext.callback = plpgsql_exec_error_callback;
1168  plerrcontext.arg = &estate;
1169  plerrcontext.previous = error_context_stack;
1170  error_context_stack = &plerrcontext;
1171 
1172  /*
1173  * Make local execution copies of all the datums
1174  */
1175  estate.err_text = gettext_noop("during initialization of execution state");
1176  copy_plpgsql_datums(&estate, func);
1177 
1178  /*
1179  * Let the instrumentation plugin peek at this function
1180  */
1181  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
1182  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1183 
1184  /*
1185  * Now call the toplevel block of statements
1186  */
1187  estate.err_text = NULL;
1188  rc = exec_toplevel_block(&estate, func->action);
1189  if (rc != PLPGSQL_RC_RETURN)
1190  {
1191  estate.err_text = NULL;
1192  ereport(ERROR,
1193  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1194  errmsg("control reached end of trigger procedure without RETURN")));
1195  }
1196 
1197  estate.err_text = gettext_noop("during function exit");
1198 
1199  /*
1200  * Let the instrumentation plugin peek at this function
1201  */
1202  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
1203  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1204 
1205  /* Clean up any leftover temporary memory */
1206  plpgsql_destroy_econtext(&estate);
1207  exec_eval_cleanup(&estate);
1208  /* stmt_mcontext will be destroyed when function's main context is */
1209 
1210  /*
1211  * Pop the error context stack
1212  */
1213  error_context_stack = plerrcontext.previous;
1214 }
#define gettext_noop(x)
Definition: c.h:1135
static void exec_eval_cleanup(PLpgSQL_execstate *estate)
Definition: pl_exec.c:4115
static void plpgsql_exec_error_callback(void *arg)
Definition: pl_exec.c:1220
static void plpgsql_estate_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func, ReturnSetInfo *rsi, EState *simple_eval_estate, ResourceOwner simple_eval_resowner)
Definition: pl_exec.c:3963
static int exec_toplevel_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
Definition: pl_exec.c:1611
static void plpgsql_destroy_econtext(PLpgSQL_execstate *estate)
Definition: pl_exec.c:8390
static void copy_plpgsql_datums(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: pl_exec.c:1287
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:56
const char * err_text
Definition: plpgsql.h:1092
EventTriggerData * evtrigdata
Definition: plpgsql.h:1025
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:1137
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:1138

References PLpgSQL_function::action, ErrorContextCallback::arg, ErrorContextCallback::callback, copy_plpgsql_datums(), ereport, PLpgSQL_execstate::err_text, errcode(), errmsg(), ERROR, error_context_stack, PLpgSQL_execstate::evtrigdata, exec_eval_cleanup(), exec_toplevel_block(), PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, gettext_noop, plpgsql_destroy_econtext(), plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, and ErrorContextCallback::previous.

Referenced by plpgsql_call_handler().

◆ plpgsql_exec_function()

Datum plpgsql_exec_function ( PLpgSQL_function func,
FunctionCallInfo  fcinfo,
EState simple_eval_estate,
ResourceOwner  simple_eval_resowner,
ResourceOwner  procedure_resowner,
bool  atomic 
)

Definition at line 471 of file pl_exec.c.

476 {
477  PLpgSQL_execstate estate;
478  ErrorContextCallback plerrcontext;
479  int i;
480  int rc;
481 
482  /*
483  * Setup the execution state
484  */
485  plpgsql_estate_setup(&estate, func, (ReturnSetInfo *) fcinfo->resultinfo,
486  simple_eval_estate, simple_eval_resowner);
487  estate.procedure_resowner = procedure_resowner;
488  estate.atomic = atomic;
489 
490  /*
491  * Setup error traceback support for ereport()
492  */
493  plerrcontext.callback = plpgsql_exec_error_callback;
494  plerrcontext.arg = &estate;
495  plerrcontext.previous = error_context_stack;
496  error_context_stack = &plerrcontext;
497 
498  /*
499  * Make local execution copies of all the datums
500  */
501  estate.err_text = gettext_noop("during initialization of execution state");
502  copy_plpgsql_datums(&estate, func);
503 
504  /*
505  * Store the actual call argument values into the appropriate variables
506  */
507  estate.err_text = gettext_noop("while storing call arguments into local variables");
508  for (i = 0; i < func->fn_nargs; i++)
509  {
510  int n = func->fn_argvarnos[i];
511 
512  switch (estate.datums[n]->dtype)
513  {
514  case PLPGSQL_DTYPE_VAR:
515  {
516  PLpgSQL_var *var = (PLpgSQL_var *) estate.datums[n];
517 
518  assign_simple_var(&estate, var,
519  fcinfo->args[i].value,
520  fcinfo->args[i].isnull,
521  false);
522 
523  /*
524  * Force any array-valued parameter to be stored in
525  * expanded form in our local variable, in hopes of
526  * improving efficiency of uses of the variable. (This is
527  * a hack, really: why only arrays? Need more thought
528  * about which cases are likely to win. See also
529  * typisarray-specific heuristic in exec_assign_value.)
530  *
531  * Special cases: If passed a R/W expanded pointer, assume
532  * we can commandeer the object rather than having to copy
533  * it. If passed a R/O expanded pointer, just keep it as
534  * the value of the variable for the moment. (We'll force
535  * it to R/W if the variable gets modified, but that may
536  * very well never happen.)
537  */
538  if (!var->isnull && var->datatype->typisarray)
539  {
541  {
542  /* take ownership of R/W object */
543  assign_simple_var(&estate, var,
545  estate.datum_context),
546  false,
547  true);
548  }
550  {
551  /* R/O pointer, keep it as-is until assigned to */
552  }
553  else
554  {
555  /* flat array, so force to expanded form */
556  assign_simple_var(&estate, var,
557  expand_array(var->value,
558  estate.datum_context,
559  NULL),
560  false,
561  true);
562  }
563  }
564  }
565  break;
566 
567  case PLPGSQL_DTYPE_REC:
568  {
569  PLpgSQL_rec *rec = (PLpgSQL_rec *) estate.datums[n];
570 
571  if (!fcinfo->args[i].isnull)
572  {
573  /* Assign row value from composite datum */
574  exec_move_row_from_datum(&estate,
575  (PLpgSQL_variable *) rec,
576  fcinfo->args[i].value);
577  }
578  else
579  {
580  /* If arg is null, set variable to null */
581  exec_move_row(&estate, (PLpgSQL_variable *) rec,
582  NULL, NULL);
583  }
584  /* clean up after exec_move_row() */
585  exec_eval_cleanup(&estate);
586  }
587  break;
588 
589  default:
590  /* Anything else should not be an argument variable */
591  elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
592  }
593  }
594 
595  estate.err_text = gettext_noop("during function entry");
596 
597  /*
598  * Set the magic variable FOUND to false
599  */
600  exec_set_found(&estate, false);
601 
602  /*
603  * Let the instrumentation plugin peek at this function
604  */
605  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
606  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
607 
608  /*
609  * Now call the toplevel block of statements
610  */
611  estate.err_text = NULL;
612  rc = exec_toplevel_block(&estate, func->action);
613  if (rc != PLPGSQL_RC_RETURN)
614  {
615  estate.err_text = NULL;
616  ereport(ERROR,
617  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
618  errmsg("control reached end of function without RETURN")));
619  }
620 
621  /*
622  * We got a return value - process it
623  */
624  estate.err_text = gettext_noop("while casting return value to function's return type");
625 
626  fcinfo->isnull = estate.retisnull;
627 
628  if (estate.retisset)
629  {
630  ReturnSetInfo *rsi = estate.rsi;
631 
632  /* Check caller can handle a set result */
633  if (!rsi || !IsA(rsi, ReturnSetInfo))
634  ereport(ERROR,
635  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
636  errmsg("set-valued function called in context that cannot accept a set")));
637 
638  if (!(rsi->allowedModes & SFRM_Materialize))
639  ereport(ERROR,
640  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
641  errmsg("materialize mode required, but it is not allowed in this context")));
642 
644 
645  /* If we produced any tuples, send back the result */
646  if (estate.tuple_store)
647  {
648  MemoryContext oldcxt;
649 
650  rsi->setResult = estate.tuple_store;
651  oldcxt = MemoryContextSwitchTo(estate.tuple_store_cxt);
653  MemoryContextSwitchTo(oldcxt);
654  }
655  estate.retval = (Datum) 0;
656  fcinfo->isnull = true;
657  }
658  else if (!estate.retisnull)
659  {
660  /*
661  * Cast result value to function's declared result type, and copy it
662  * out to the upper executor memory context. We must treat tuple
663  * results specially in order to deal with cases like rowtypes
664  * involving dropped columns.
665  */
666  if (estate.retistuple)
667  {
668  /* Don't need coercion if rowtype is known to match */
669  if (func->fn_rettype == estate.rettype &&
670  func->fn_rettype != RECORDOID)
671  {
672  /*
673  * Copy the tuple result into upper executor memory context.
674  * However, if we have a R/W expanded datum, we can just
675  * transfer its ownership out to the upper context.
676  */
677  estate.retval = SPI_datumTransfer(estate.retval,
678  false,
679  -1);
680  }
681  else
682  {
683  /*
684  * Need to look up the expected result type. XXX would be
685  * better to cache the tupdesc instead of repeating
686  * get_call_result_type(), but the only easy place to save it
687  * is in the PLpgSQL_function struct, and that's too
688  * long-lived: composite types could change during the
689  * existence of a PLpgSQL_function.
690  */
691  Oid resultTypeId;
692  TupleDesc tupdesc;
693 
694  switch (get_call_result_type(fcinfo, &resultTypeId, &tupdesc))
695  {
696  case TYPEFUNC_COMPOSITE:
697  /* got the expected result rowtype, now coerce it */
698  coerce_function_result_tuple(&estate, tupdesc);
699  break;
701  /* got the expected result rowtype, now coerce it */
702  coerce_function_result_tuple(&estate, tupdesc);
703  /* and check domain constraints */
704  /* XXX allowing caching here would be good, too */
705  domain_check(estate.retval, false, resultTypeId,
706  NULL, NULL);
707  break;
708  case TYPEFUNC_RECORD:
709 
710  /*
711  * Failed to determine actual type of RECORD. We
712  * could raise an error here, but what this means in
713  * practice is that the caller is expecting any old
714  * generic rowtype, so we don't really need to be
715  * restrictive. Pass back the generated result as-is.
716  */
717  estate.retval = SPI_datumTransfer(estate.retval,
718  false,
719  -1);
720  break;
721  default:
722  /* shouldn't get here if retistuple is true ... */
723  elog(ERROR, "return type must be a row type");
724  break;
725  }
726  }
727  }
728  else
729  {
730  /* Scalar case: use exec_cast_value */
731  estate.retval = exec_cast_value(&estate,
732  estate.retval,
733  &fcinfo->isnull,
734  estate.rettype,
735  -1,
736  func->fn_rettype,
737  -1);
738 
739  /*
740  * If the function's return type isn't by value, copy the value
741  * into upper executor memory context. However, if we have a R/W
742  * expanded datum, we can just transfer its ownership out to the
743  * upper executor context.
744  */
745  if (!fcinfo->isnull && !func->fn_retbyval)
746  estate.retval = SPI_datumTransfer(estate.retval,
747  false,
748  func->fn_rettyplen);
749  }
750  }
751  else
752  {
753  /*
754  * We're returning a NULL, which normally requires no conversion work
755  * regardless of datatypes. But, if we are casting it to a domain
756  * return type, we'd better check that the domain's constraints pass.
757  */
758  if (func->fn_retisdomain)
759  estate.retval = exec_cast_value(&estate,
760  estate.retval,
761  &fcinfo->isnull,
762  estate.rettype,
763  -1,
764  func->fn_rettype,
765  -1);
766  }
767 
768  estate.err_text = gettext_noop("during function exit");
769 
770  /*
771  * Let the instrumentation plugin peek at this function
772  */
773  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
774  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
775 
776  /* Clean up any leftover temporary memory */
777  plpgsql_destroy_econtext(&estate);
778  exec_eval_cleanup(&estate);
779  /* stmt_mcontext will be destroyed when function's main context is */
780 
781  /*
782  * Pop the error context stack
783  */
784  error_context_stack = plerrcontext.previous;
785 
786  /*
787  * Return the function's result
788  */
789  return estate.retval;
790 }
Datum expand_array(Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
Definition: domains.c:327
@ SFRM_Materialize
Definition: execnodes.h:309
Datum TransferExpandedObject(Datum d, MemoryContext new_parent)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
@ TYPEFUNC_RECORD
Definition: funcapi.h:151
@ TYPEFUNC_COMPOSITE_DOMAIN
Definition: funcapi.h:150
#define IsA(nodeptr, _type_)
Definition: nodes.h:168
static void coerce_function_result_tuple(PLpgSQL_execstate *estate, TupleDesc tupdesc)
Definition: pl_exec.c:801
static void exec_move_row_from_datum(PLpgSQL_execstate *estate, PLpgSQL_variable *target, Datum value)
Definition: pl_exec.c:7397
static Datum exec_cast_value(PLpgSQL_execstate *estate, Datum value, bool *isnull, Oid valtype, int32 valtypmod, Oid reqtype, int32 reqtypmod)
Definition: pl_exec.c:7694
static void exec_set_found(PLpgSQL_execstate *estate, bool state)
Definition: pl_exec.c:8305
static void assign_simple_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, Datum newvalue, bool isnull, bool freeable)
Definition: pl_exec.c:8481
static void exec_move_row(PLpgSQL_execstate *estate, PLpgSQL_variable *target, HeapTuple tup, TupleDesc tupdesc)
Definition: pl_exec.c:6723
#define VARATT_IS_EXTERNAL_EXPANDED_RO(PTR)
Definition: postgres.h:332
uintptr_t Datum
Definition: postgres.h:412
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:334
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
Datum SPI_datumTransfer(Datum value, bool typByVal, int typLen)
Definition: spi.c:1359
fmNodePtr resultinfo
Definition: fmgr.h:89
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:423
PLpgSQL_datum ** datums
Definition: plpgsql.h:1057
ResourceOwner procedure_resowner
Definition: plpgsql.h:1074
Tuplestorestate * tuple_store
Definition: plpgsql.h:1042
MemoryContext tuple_store_cxt
Definition: plpgsql.h:1044
TupleDesc tuple_store_desc
Definition: plpgsql.h:1043
MemoryContext datum_context
Definition: plpgsql.h:1059
ReturnSetInfo * rsi
Definition: plpgsql.h:1046
bool fn_retbyval
Definition: plpgsql.h:978
bool fn_retisdomain
Definition: plpgsql.h:980
int fn_argvarnos[FUNC_MAX_ARGS]
Definition: plpgsql.h:986
bool typisarray
Definition: plpgsql.h:206
SetFunctionReturnMode returnMode
Definition: execnodes.h:328
TupleDesc setDesc
Definition: execnodes.h:332
Tuplestorestate * setResult
Definition: execnodes.h:331
int allowedModes
Definition: execnodes.h:326
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111

References PLpgSQL_function::action, ReturnSetInfo::allowedModes, ErrorContextCallback::arg, FunctionCallInfoBaseData::args, assign_simple_var(), PLpgSQL_execstate::atomic, ErrorContextCallback::callback, coerce_function_result_tuple(), copy_plpgsql_datums(), CreateTupleDescCopy(), PLpgSQL_var::datatype, PLpgSQL_execstate::datum_context, DatumGetPointer(), PLpgSQL_function::datums, PLpgSQL_execstate::datums, domain_check(), PLpgSQL_datum::dtype, elog(), ereport, PLpgSQL_execstate::err_text, errcode(), errmsg(), ERROR, error_context_stack, exec_cast_value(), exec_eval_cleanup(), exec_move_row(), exec_move_row_from_datum(), exec_set_found(), exec_toplevel_block(), expand_array(), PLpgSQL_function::fn_argvarnos, PLpgSQL_function::fn_nargs, PLpgSQL_function::fn_retbyval, PLpgSQL_function::fn_retisdomain, PLpgSQL_function::fn_rettype, PLpgSQL_function::fn_rettyplen, PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, get_call_result_type(), gettext_noop, i, if(), IsA, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, PLpgSQL_var::isnull, MemoryContextSwitchTo(), plpgsql_destroy_econtext(), PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_VAR, plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, ErrorContextCallback::previous, PLpgSQL_execstate::procedure_resowner, FunctionCallInfoBaseData::resultinfo, PLpgSQL_execstate::retisnull, PLpgSQL_execstate::retisset, PLpgSQL_execstate::retistuple, PLpgSQL_execstate::rettype, ReturnSetInfo::returnMode, PLpgSQL_execstate::retval, PLpgSQL_execstate::rsi, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, SPI_datumTransfer(), TransferExpandedObject(), PLpgSQL_execstate::tuple_store, PLpgSQL_execstate::tuple_store_cxt, PLpgSQL_execstate::tuple_store_desc, TYPEFUNC_COMPOSITE, TYPEFUNC_COMPOSITE_DOMAIN, TYPEFUNC_RECORD, PLpgSQL_type::typisarray, NullableDatum::value, PLpgSQL_var::value, VARATT_IS_EXTERNAL_EXPANDED_RO, and VARATT_IS_EXTERNAL_EXPANDED_RW.

Referenced by plpgsql_call_handler(), and plpgsql_inline_handler().

◆ plpgsql_exec_get_datum_type()

PGDLLEXPORT Oid plpgsql_exec_get_datum_type ( PLpgSQL_execstate estate,
PLpgSQL_datum datum 
)

Definition at line 5435 of file pl_exec.c.

5437 {
5438  Oid typeid;
5439 
5440  switch (datum->dtype)
5441  {
5442  case PLPGSQL_DTYPE_VAR:
5443  case PLPGSQL_DTYPE_PROMISE:
5444  {
5445  PLpgSQL_var *var = (PLpgSQL_var *) datum;
5446 
5447  typeid = var->datatype->typoid;
5448  break;
5449  }
5450 
5451  case PLPGSQL_DTYPE_REC:
5452  {
5453  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
5454 
5455  if (rec->erh == NULL || rec->rectypeid != RECORDOID)
5456  {
5457  /* Report variable's declared type */
5458  typeid = rec->rectypeid;
5459  }
5460  else
5461  {
5462  /* Report record's actual type if declared RECORD */
5463  typeid = rec->erh->er_typeid;
5464  }
5465  break;
5466  }
5467 
5469  {
5470  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
5471  PLpgSQL_rec *rec;
5472 
5473  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
5474 
5475  /*
5476  * If record variable is NULL, instantiate it if it has a
5477  * named composite type, else complain. (This won't change
5478  * the logical state of the record: it's still NULL.)
5479  */
5480  if (rec->erh == NULL)
5481  instantiate_empty_record_variable(estate, rec);
5482 
5483  /*
5484  * Look up the field's properties if we have not already, or
5485  * if the tuple descriptor ID changed since last time.
5486  */
5487  if (unlikely(recfield->rectupledescid != rec->erh->er_tupdesc_id))
5488  {
5490  recfield->fieldname,
5491  &recfield->finfo))
5492  ereport(ERROR,
5493  (errcode(ERRCODE_UNDEFINED_COLUMN),
5494  errmsg("record \"%s\" has no field \"%s\"",
5495  rec->refname, recfield->fieldname)));
5496  recfield->rectupledescid = rec->erh->er_tupdesc_id;
5497  }
5498 
5499  typeid = recfield->finfo.ftypeid;
5500  break;
5501  }
5502 
5503  default:
5504  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5505  typeid = InvalidOid; /* keep compiler quiet */
5506  break;
5507  }
5508 
5509  return typeid;
5510 }
#define unlikely(x)
Definition: c.h:295
bool expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname, ExpandedRecordFieldInfo *finfo)
static void instantiate_empty_record_variable(PLpgSQL_execstate *estate, PLpgSQL_rec *rec)
Definition: pl_exec.c:7630
ExpandedRecordFieldInfo finfo
Definition: plpgsql.h:429

References PLpgSQL_var::datatype, PLpgSQL_execstate::datums, PLpgSQL_datum::dtype, elog(), ExpandedRecordHeader::er_tupdesc_id, ExpandedRecordHeader::er_typeid, ereport, PLpgSQL_rec::erh, errcode(), errmsg(), ERROR, expanded_record_lookup_field(), PLpgSQL_recfield::fieldname, PLpgSQL_recfield::finfo, ExpandedRecordFieldInfo::ftypeid, instantiate_empty_record_variable(), InvalidOid, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_VAR, PLpgSQL_recfield::recparentno, PLpgSQL_recfield::rectupledescid, PLpgSQL_rec::rectypeid, PLpgSQL_rec::refname, PLpgSQL_type::typoid, and unlikely.

Referenced by exec_stmt_foreach_a().

◆ plpgsql_exec_get_datum_type_info()

void plpgsql_exec_get_datum_type_info ( PLpgSQL_execstate estate,
PLpgSQL_datum datum,
Oid typeId,
int32 typMod,
Oid collation 
)

Definition at line 5520 of file pl_exec.c.

5523 {
5524  switch (datum->dtype)
5525  {
5526  case PLPGSQL_DTYPE_VAR:
5527  case PLPGSQL_DTYPE_PROMISE:
5528  {
5529  PLpgSQL_var *var = (PLpgSQL_var *) datum;
5530 
5531  *typeId = var->datatype->typoid;
5532  *typMod = var->datatype->atttypmod;
5533  *collation = var->datatype->collation;
5534  break;
5535  }
5536 
5537  case PLPGSQL_DTYPE_REC:
5538  {
5539  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
5540 
5541  if (rec->erh == NULL || rec->rectypeid != RECORDOID)
5542  {
5543  /* Report variable's declared type */
5544  *typeId = rec->rectypeid;
5545  *typMod = -1;
5546  }
5547  else
5548  {
5549  /* Report record's actual type if declared RECORD */
5550  *typeId = rec->erh->er_typeid;
5551  /* do NOT return the mutable typmod of a RECORD variable */
5552  *typMod = -1;
5553  }
5554  /* composite types are never collatable */
5555  *collation = InvalidOid;
5556  break;
5557  }
5558 
5560  {
5561  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
5562  PLpgSQL_rec *rec;
5563 
5564  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
5565 
5566  /*
5567  * If record variable is NULL, instantiate it if it has a
5568  * named composite type, else complain. (This won't change
5569  * the logical state of the record: it's still NULL.)
5570  */
5571  if (rec->erh == NULL)
5572  instantiate_empty_record_variable(estate, rec);
5573 
5574  /*
5575  * Look up the field's properties if we have not already, or
5576  * if the tuple descriptor ID changed since last time.
5577  */
5578  if (unlikely(recfield->rectupledescid != rec->erh->er_tupdesc_id))
5579  {
5581  recfield->fieldname,
5582  &recfield->finfo))
5583  ereport(ERROR,
5584  (errcode(ERRCODE_UNDEFINED_COLUMN),
5585  errmsg("record \"%s\" has no field \"%s\"",
5586  rec->refname, recfield->fieldname)));
5587  recfield->rectupledescid = rec->erh->er_tupdesc_id;
5588  }
5589 
5590  *typeId = recfield->finfo.ftypeid;
5591  *typMod = recfield->finfo.ftypmod;
5592  *collation = recfield->finfo.fcollation;
5593  break;
5594  }
5595 
5596  default:
5597  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5598  *typeId = InvalidOid; /* keep compiler quiet */
5599  *typMod = -1;
5600  *collation = InvalidOid;
5601  break;
5602  }
5603 }
Oid collation
Definition: plpgsql.h:205

References PLpgSQL_type::atttypmod, PLpgSQL_type::collation, PLpgSQL_var::datatype, PLpgSQL_execstate::datums, PLpgSQL_datum::dtype, elog(), ExpandedRecordHeader::er_tupdesc_id, ExpandedRecordHeader::er_typeid, ereport, PLpgSQL_rec::erh, errcode(), errmsg(), ERROR, expanded_record_lookup_field(), ExpandedRecordFieldInfo::fcollation, PLpgSQL_recfield::fieldname, PLpgSQL_recfield::finfo, ExpandedRecordFieldInfo::ftypeid, ExpandedRecordFieldInfo::ftypmod, instantiate_empty_record_variable(), InvalidOid, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_VAR, PLpgSQL_recfield::recparentno, PLpgSQL_recfield::rectupledescid, PLpgSQL_rec::rectypeid, PLpgSQL_rec::refname, PLpgSQL_type::typoid, and unlikely.

Referenced by make_datum_param().

◆ plpgsql_exec_trigger()

HeapTuple plpgsql_exec_trigger ( PLpgSQL_function func,
TriggerData trigdata 
)

Definition at line 912 of file pl_exec.c.

914 {
915  PLpgSQL_execstate estate;
916  ErrorContextCallback plerrcontext;
917  int rc;
918  TupleDesc tupdesc;
919  PLpgSQL_rec *rec_new,
920  *rec_old;
921  HeapTuple rettup;
922 
923  /*
924  * Setup the execution state
925  */
926  plpgsql_estate_setup(&estate, func, NULL, NULL, NULL);
927  estate.trigdata = trigdata;
928 
929  /*
930  * Setup error traceback support for ereport()
931  */
932  plerrcontext.callback = plpgsql_exec_error_callback;
933  plerrcontext.arg = &estate;
934  plerrcontext.previous = error_context_stack;
935  error_context_stack = &plerrcontext;
936 
937  /*
938  * Make local execution copies of all the datums
939  */
940  estate.err_text = gettext_noop("during initialization of execution state");
941  copy_plpgsql_datums(&estate, func);
942 
943  /*
944  * Put the OLD and NEW tuples into record variables
945  *
946  * We set up expanded records for both variables even though only one may
947  * have a value. This allows record references to succeed in functions
948  * that are used for multiple trigger types. For example, we might have a
949  * test like "if (TG_OP = 'INSERT' and NEW.foo = 'xyz')", which should
950  * work regardless of the current trigger type. If a value is actually
951  * fetched from an unsupplied tuple, it will read as NULL.
952  */
953  tupdesc = RelationGetDescr(trigdata->tg_relation);
954 
955  rec_new = (PLpgSQL_rec *) (estate.datums[func->new_varno]);
956  rec_old = (PLpgSQL_rec *) (estate.datums[func->old_varno]);
957 
958  rec_new->erh = make_expanded_record_from_tupdesc(tupdesc,
959  estate.datum_context);
960  rec_old->erh = make_expanded_record_from_exprecord(rec_new->erh,
961  estate.datum_context);
962 
963  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
964  {
965  /*
966  * Per-statement triggers don't use OLD/NEW variables
967  */
968  }
969  else if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
970  {
971  expanded_record_set_tuple(rec_new->erh, trigdata->tg_trigtuple,
972  false, false);
973  }
974  else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
975  {
976  expanded_record_set_tuple(rec_new->erh, trigdata->tg_newtuple,
977  false, false);
978  expanded_record_set_tuple(rec_old->erh, trigdata->tg_trigtuple,
979  false, false);
980 
981  /*
982  * In BEFORE trigger, stored generated columns are not computed yet,
983  * so make them null in the NEW row. (Only needed in UPDATE branch;
984  * in the INSERT case, they are already null, but in UPDATE, the field
985  * still contains the old value.) Alternatively, we could construct a
986  * whole new row structure without the generated columns, but this way
987  * seems more efficient and potentially less confusing.
988  */
989  if (tupdesc->constr && tupdesc->constr->has_generated_stored &&
990  TRIGGER_FIRED_BEFORE(trigdata->tg_event))
991  {
992  for (int i = 0; i < tupdesc->natts; i++)
993  if (TupleDescAttr(tupdesc, i)->attgenerated == ATTRIBUTE_GENERATED_STORED)
995  i + 1,
996  (Datum) 0,
997  true, /* isnull */
998  false, false);
999  }
1000  }
1001  else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
1002  {
1003  expanded_record_set_tuple(rec_old->erh, trigdata->tg_trigtuple,
1004  false, false);
1005  }
1006  else
1007  elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE");
1008 
1009  /* Make transition tables visible to this SPI connection */
1010  rc = SPI_register_trigger_data(trigdata);
1011  Assert(rc >= 0);
1012 
1013  estate.err_text = gettext_noop("during function entry");
1014 
1015  /*
1016  * Set the magic variable FOUND to false
1017  */
1018  exec_set_found(&estate, false);
1019 
1020  /*
1021  * Let the instrumentation plugin peek at this function
1022  */
1023  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
1024  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1025 
1026  /*
1027  * Now call the toplevel block of statements
1028  */
1029  estate.err_text = NULL;
1030  rc = exec_toplevel_block(&estate, func->action);
1031  if (rc != PLPGSQL_RC_RETURN)
1032  {
1033  estate.err_text = NULL;
1034  ereport(ERROR,
1035  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1036  errmsg("control reached end of trigger procedure without RETURN")));
1037  }
1038 
1039  estate.err_text = gettext_noop("during function exit");
1040 
1041  if (estate.retisset)
1042  ereport(ERROR,
1043  (errcode(ERRCODE_DATATYPE_MISMATCH),
1044  errmsg("trigger procedure cannot return a set")));
1045 
1046  /*
1047  * Check that the returned tuple structure has the same attributes, the
1048  * relation that fired the trigger has. A per-statement trigger always
1049  * needs to return NULL, so we ignore any return value the function itself
1050  * produces (XXX: is this a good idea?)
1051  *
1052  * XXX This way it is possible, that the trigger returns a tuple where
1053  * attributes don't have the correct atttypmod's length. It's up to the
1054  * trigger's programmer to ensure that this doesn't happen. Jan
1055  */
1056  if (estate.retisnull || !TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
1057  rettup = NULL;
1058  else
1059  {
1060  TupleDesc retdesc;
1061  TupleConversionMap *tupmap;
1062 
1063  /* We assume exec_stmt_return verified that result is composite */
1064  Assert(type_is_rowtype(estate.rettype));
1065 
1066  /* We can special-case expanded records for speed */
1068  {
1070 
1071  Assert(erh->er_magic == ER_MAGIC);
1072 
1073  /* Extract HeapTuple and TupleDesc */
1074  rettup = expanded_record_get_tuple(erh);
1075  Assert(rettup);
1076  retdesc = expanded_record_get_tupdesc(erh);
1077 
1078  if (retdesc != RelationGetDescr(trigdata->tg_relation))
1079  {
1080  /* check rowtype compatibility */
1081  tupmap = convert_tuples_by_position(retdesc,
1082  RelationGetDescr(trigdata->tg_relation),
1083  gettext_noop("returned row structure does not match the structure of the triggering table"));
1084  /* it might need conversion */
1085  if (tupmap)
1086  rettup = execute_attr_map_tuple(rettup, tupmap);
1087  /* no need to free map, we're about to return anyway */
1088  }
1089 
1090  /*
1091  * Copy tuple to upper executor memory. But if user just did
1092  * "return new" or "return old" without changing anything, there's
1093  * no need to copy; we can return the original tuple (which will
1094  * save a few cycles in trigger.c as well as here).
1095  */
1096  if (rettup != trigdata->tg_newtuple &&
1097  rettup != trigdata->tg_trigtuple)
1098  rettup = SPI_copytuple(rettup);
1099  }
1100  else
1101  {
1102  /* Convert composite datum to a HeapTuple and TupleDesc */
1103  HeapTupleData tmptup;
1104 
1105  retdesc = deconstruct_composite_datum(estate.retval, &tmptup);
1106  rettup = &tmptup;
1107 
1108  /* check rowtype compatibility */
1109  tupmap = convert_tuples_by_position(retdesc,
1110  RelationGetDescr(trigdata->tg_relation),
1111  gettext_noop("returned row structure does not match the structure of the triggering table"));
1112  /* it might need conversion */
1113  if (tupmap)
1114  rettup = execute_attr_map_tuple(rettup, tupmap);
1115 
1116  ReleaseTupleDesc(retdesc);
1117  /* no need to free map, we're about to return anyway */
1118 
1119  /* Copy tuple to upper executor memory */
1120  rettup = SPI_copytuple(rettup);
1121  }
1122  }
1123 
1124  /*
1125  * Let the instrumentation plugin peek at this function
1126  */
1127  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
1128  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1129 
1130  /* Clean up any leftover temporary memory */
1131  plpgsql_destroy_econtext(&estate);
1132  exec_eval_cleanup(&estate);
1133  /* stmt_mcontext will be destroyed when function's main context is */
1134 
1135  /*
1136  * Pop the error context stack
1137  */
1138  error_context_stack = plerrcontext.previous;
1139 
1140  /*
1141  * Return the trigger's result
1142  */
1143  return rettup;
1144 }
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
ExpandedRecordHeader * make_expanded_record_from_tupdesc(TupleDesc tupdesc, MemoryContext parentcontext)
void expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber, Datum newValue, bool isnull, bool expand_external, bool check_constraints)
ExpandedRecordHeader * make_expanded_record_from_exprecord(ExpandedRecordHeader *olderh, MemoryContext parentcontext)
void expanded_record_set_tuple(ExpandedRecordHeader *erh, HeapTuple tuple, bool copy, bool expand_external)
HeapTuple expanded_record_get_tuple(ExpandedRecordHeader *erh)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2613
static TupleDesc deconstruct_composite_datum(Datum value, HeapTupleData *tmptup)
Definition: pl_exec.c:7366
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:336
#define RelationGetDescr(relation)
Definition: rel.h:527
int SPI_register_trigger_data(TriggerData *tdata)
Definition: spi.c:3336
HeapTuple SPI_copytuple(HeapTuple tuple)
Definition: spi.c:1045
TriggerData * trigdata
Definition: plpgsql.h:1024
Relation tg_relation
Definition: trigger.h:35
TriggerEvent tg_event
Definition: trigger.h:34
HeapTuple tg_newtuple
Definition: trigger.h:37
HeapTuple tg_trigtuple
Definition: trigger.h:36
bool has_generated_stored
Definition: tupdesc.h:45
TupleConstr * constr
Definition: tupdesc.h:85
#define TRIGGER_FIRED_BY_DELETE(event)
Definition: trigger.h:113
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:128
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:122
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:110
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:116
TupleConversionMap * convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg)
Definition: tupconvert.c:59
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:154
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References PLpgSQL_function::action, ErrorContextCallback::arg, Assert(), ErrorContextCallback::callback, TupleDescData::constr, convert_tuples_by_position(), copy_plpgsql_datums(), PLpgSQL_execstate::datum_context, DatumGetEOHP(), DatumGetPointer(), PLpgSQL_execstate::datums, deconstruct_composite_datum(), elog(), ER_MAGIC, ExpandedRecordHeader::er_magic, ereport, PLpgSQL_rec::erh, PLpgSQL_execstate::err_text, errcode(), errmsg(), ERROR, error_context_stack, exec_eval_cleanup(), exec_set_found(), exec_toplevel_block(), execute_attr_map_tuple(), expanded_record_get_tupdesc(), expanded_record_get_tuple(), expanded_record_set_field_internal(), expanded_record_set_tuple(), PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, gettext_noop, TupleConstr::has_generated_stored, i, make_expanded_record_from_exprecord(), make_expanded_record_from_tupdesc(), TupleDescData::natts, PLpgSQL_function::new_varno, PLpgSQL_function::old_varno, plpgsql_destroy_econtext(), plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, ErrorContextCallback::previous, RelationGetDescr, ReleaseTupleDesc, PLpgSQL_execstate::retisnull, PLpgSQL_execstate::retisset, PLpgSQL_execstate::rettype, PLpgSQL_execstate::retval, SPI_copytuple(), SPI_register_trigger_data(), TriggerData::tg_event, TriggerData::tg_newtuple, TriggerData::tg_relation, TriggerData::tg_trigtuple, PLpgSQL_execstate::trigdata, TRIGGER_FIRED_BEFORE, TRIGGER_FIRED_BY_DELETE, TRIGGER_FIRED_BY_INSERT, TRIGGER_FIRED_BY_UPDATE, TRIGGER_FIRED_FOR_ROW, TupleDescAttr, type_is_rowtype(), and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by plpgsql_call_handler().

◆ plpgsql_free_function_memory()

void plpgsql_free_function_memory ( PLpgSQL_function func)

Definition at line 725 of file pl_funcs.c.

726 {
727  int i;
728 
729  /* Better not call this on an in-use function */
730  Assert(func->use_count == 0);
731 
732  /* Release plans associated with variable declarations */
733  for (i = 0; i < func->ndatums; i++)
734  {
735  PLpgSQL_datum *d = func->datums[i];
736 
737  switch (d->dtype)
738  {
739  case PLPGSQL_DTYPE_VAR:
741  {
742  PLpgSQL_var *var = (PLpgSQL_var *) d;
743 
744  free_expr(var->default_val);
746  }
747  break;
748  case PLPGSQL_DTYPE_ROW:
749  break;
750  case PLPGSQL_DTYPE_REC:
751  {
752  PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
753 
754  free_expr(rec->default_val);
755  }
756  break;
758  break;
759  default:
760  elog(ERROR, "unrecognized data type: %d", d->dtype);
761  }
762  }
763  func->ndatums = 0;
764 
765  /* Release plans in statement tree */
766  if (func->action)
767  free_block(func->action);
768  func->action = NULL;
769 
770  /*
771  * And finally, release all memory except the PLpgSQL_function struct
772  * itself (which has to be kept around because there may be multiple
773  * fn_extra pointers to it).
774  */
775  if (func->fn_cxt)
777  func->fn_cxt = NULL;
778 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:376
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:478
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:715
unsigned long use_count
Definition: plpgsql.h:1014
MemoryContext fn_cxt
Definition: plpgsql.h:974
PLpgSQL_expr * default_val
Definition: plpgsql.h:396

References PLpgSQL_function::action, Assert(), PLpgSQL_var::cursor_explicit_expr, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_rec::default_val, PLpgSQL_datum::dtype, elog(), ERROR, PLpgSQL_function::fn_cxt, free_block(), free_expr(), i, MemoryContextDelete(), PLpgSQL_function::ndatums, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, and PLpgSQL_function::use_count.

Referenced by delete_function(), and plpgsql_inline_handler().

◆ plpgsql_getdiag_kindname()

const char* plpgsql_getdiag_kindname ( PLpgSQL_getdiag_kind  kind)

Definition at line 300 of file pl_funcs.c.

301 {
302  switch (kind)
303  {
305  return "ROW_COUNT";
307  return "PG_CONTEXT";
309  return "PG_EXCEPTION_CONTEXT";
311  return "PG_EXCEPTION_DETAIL";
313  return "PG_EXCEPTION_HINT";
315  return "RETURNED_SQLSTATE";
317  return "COLUMN_NAME";
319  return "CONSTRAINT_NAME";
321  return "PG_DATATYPE_NAME";
323  return "MESSAGE_TEXT";
325  return "TABLE_NAME";
327  return "SCHEMA_NAME";
328  }
329 
330  return "unknown";
331 }

References PLPGSQL_GETDIAG_COLUMN_NAME, PLPGSQL_GETDIAG_CONSTRAINT_NAME, PLPGSQL_GETDIAG_CONTEXT, PLPGSQL_GETDIAG_DATATYPE_NAME, PLPGSQL_GETDIAG_ERROR_CONTEXT, PLPGSQL_GETDIAG_ERROR_DETAIL, PLPGSQL_GETDIAG_ERROR_HINT, PLPGSQL_GETDIAG_MESSAGE_TEXT, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, PLPGSQL_GETDIAG_ROW_COUNT, PLPGSQL_GETDIAG_SCHEMA_NAME, and PLPGSQL_GETDIAG_TABLE_NAME.

Referenced by dump_getdiag().

◆ plpgsql_HashTableInit()

void plpgsql_HashTableInit ( void  )

Definition at line 2609 of file pl_comp.c.

2610 {
2611  HASHCTL ctl;
2612 
2613  /* don't allow double-initialization */
2614  Assert(plpgsql_HashTable == NULL);
2615 
2616  ctl.keysize = sizeof(PLpgSQL_func_hashkey);
2617  ctl.entrysize = sizeof(plpgsql_HashEnt);
2618  plpgsql_HashTable = hash_create("PLpgSQL function hash",
2620  &ctl,
2621  HASH_ELEM | HASH_BLOBS);
2622 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
#define FUNCS_PER_USER
Definition: pl_comp.c:70
struct plpgsql_hashent plpgsql_HashEnt
static HTAB * plpgsql_HashTable
Definition: pl_comp.c:62
struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76

References Assert(), HASHCTL::entrysize, FUNCS_PER_USER, HASH_BLOBS, hash_create(), HASH_ELEM, HASHCTL::keysize, and plpgsql_HashTable.

Referenced by _PG_init().

◆ plpgsql_latest_lineno()

int plpgsql_latest_lineno ( void  )

Definition at line 572 of file pl_scanner.c.

573 {
574  return cur_line_num;
575 }
static int cur_line_num
Definition: pl_scanner.c:128

References cur_line_num.

Referenced by plpgsql_compile_error_callback().

◆ plpgsql_location_to_lineno()

int plpgsql_location_to_lineno ( int  location)

Definition at line 538 of file pl_scanner.c.

539 {
540  const char *loc;
541 
542  if (location < 0 || scanorig == NULL)
543  return 0; /* garbage in, garbage out */
544  loc = scanorig + location;
545 
546  /* be correct, but not fast, if input location goes backwards */
547  if (loc < cur_line_start)
549 
550  while (cur_line_end != NULL && loc > cur_line_end)
551  {
553  cur_line_num++;
554  cur_line_end = strchr(cur_line_start, '\n');
555  }
556 
557  return cur_line_num;
558 }
static const char * cur_line_end
Definition: pl_scanner.c:127
static void location_lineno_init(void)
Definition: pl_scanner.c:562
static const char * cur_line_start
Definition: pl_scanner.c:126

References cur_line_end, cur_line_num, cur_line_start, location_lineno_init(), and scanorig.

◆ plpgsql_ns_additem()

void plpgsql_ns_additem ( PLpgSQL_nsitem_type  itemtype,
int  itemno,
const char *  name 
)

Definition at line 92 of file pl_funcs.c.

93 {
94  PLpgSQL_nsitem *nse;
95 
96  Assert(name != NULL);
97  /* first item added must be a label */
98  Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
99 
100  nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
101  nse->itemtype = itemtype;
102  nse->itemno = itemno;
103  nse->prev = ns_top;
104  strcpy(nse->name, name);
105  ns_top = nse;
106 }
const char * name
Definition: encode.c:561
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:35
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:446
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:445
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:438

References Assert(), PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, name, PLpgSQL_nsitem::name, ns_top, palloc(), PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

Referenced by add_parameter_name(), plpgsql_build_record(), plpgsql_build_variable(), and plpgsql_ns_push().

◆ plpgsql_ns_find_nearest_loop()

PLpgSQL_nsitem* plpgsql_ns_find_nearest_loop ( PLpgSQL_nsitem ns_cur)

Definition at line 214 of file pl_funcs.c.

215 {
216  while (ns_cur != NULL)
217  {
218  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
219  ns_cur->itemno == PLPGSQL_LABEL_LOOP)
220  return ns_cur;
221  ns_cur = ns_cur->prev;
222  }
223 
224  return NULL; /* no loop found */
225 }

References PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, PLPGSQL_LABEL_LOOP, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_init()

void plpgsql_ns_init ( void  )

Definition at line 43 of file pl_funcs.c.

44 {
45  ns_top = NULL;
46 }

References ns_top.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_ns_lookup()

PGDLLEXPORT PLpgSQL_nsitem* plpgsql_ns_lookup ( PLpgSQL_nsitem ns_cur,
bool  localmode,
const char *  name1,
const char *  name2,
const char *  name3,
int *  names_used 
)

Definition at line 130 of file pl_funcs.c.

133 {
134  /* Outer loop iterates once per block level in the namespace chain */
135  while (ns_cur != NULL)
136  {
137  PLpgSQL_nsitem *nsitem;
138 
139  /* Check this level for unqualified match to variable name */
140  for (nsitem = ns_cur;
141  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
142  nsitem = nsitem->prev)
143  {
144  if (strcmp(nsitem->name, name1) == 0)
145  {
146  if (name2 == NULL ||
147  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
148  {
149  if (names_used)
150  *names_used = 1;
151  return nsitem;
152  }
153  }
154  }
155 
156  /* Check this level for qualified match to variable name */
157  if (name2 != NULL &&
158  strcmp(nsitem->name, name1) == 0)
159  {
160  for (nsitem = ns_cur;
161  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
162  nsitem = nsitem->prev)
163  {
164  if (strcmp(nsitem->name, name2) == 0)
165  {
166  if (name3 == NULL ||
167  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
168  {
169  if (names_used)
170  *names_used = 2;
171  return nsitem;
172  }
173  }
174  }
175  }
176 
177  if (localmode)
178  break; /* do not look into upper levels */
179 
180  ns_cur = nsitem->prev;
181  }
182 
183  /* This is just to suppress possibly-uninitialized-variable warnings */
184  if (names_used)
185  *names_used = 0;
186  return NULL; /* No match found */
187 }

References PLpgSQL_nsitem::itemtype, PLpgSQL_nsitem::name, PLPGSQL_NSTYPE_LABEL, PLPGSQL_NSTYPE_VAR, and PLpgSQL_nsitem::prev.

Referenced by add_parameter_name(), plpgsql_param_ref(), plpgsql_parse_cwordtype(), plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_parse_wordtype(), and resolve_column_ref().

◆ plpgsql_ns_lookup_label()

PLpgSQL_nsitem* plpgsql_ns_lookup_label ( PLpgSQL_nsitem ns_cur,
const char *  name 
)

Definition at line 195 of file pl_funcs.c.

196 {
197  while (ns_cur != NULL)
198  {
199  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
200  strcmp(ns_cur->name, name) == 0)
201  return ns_cur;
202  ns_cur = ns_cur->prev;
203  }
204 
205  return NULL; /* label not found */
206 }

References PLpgSQL_nsitem::itemtype, name, PLpgSQL_nsitem::name, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_pop()

void plpgsql_ns_pop ( void  )

Definition at line 67 of file pl_funcs.c.

68 {
69  Assert(ns_top != NULL);
71  ns_top = ns_top->prev;
72  ns_top = ns_top->prev;
73 }

References Assert(), PLpgSQL_nsitem::itemtype, ns_top, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_push()

void plpgsql_ns_push ( const char *  label,
PLpgSQL_label_type  label_type 
)

Definition at line 54 of file pl_funcs.c.

55 {
56  if (label == NULL)
57  label = "";
58  plpgsql_ns_additem(PLPGSQL_NSTYPE_LABEL, (int) label_type, label);
59 }
static char * label

References label, plpgsql_ns_additem(), and PLPGSQL_NSTYPE_LABEL.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_ns_top()

PLpgSQL_nsitem* plpgsql_ns_top ( void  )

◆ plpgsql_parse_cwordrowtype()

PLpgSQL_type* plpgsql_parse_cwordrowtype ( List idents)

Definition at line 1833 of file pl_comp.c.

1834 {
1835  Oid classOid;
1836  Oid typOid;
1837  RangeVar *relvar;
1838  MemoryContext oldCxt;
1839 
1840  /*
1841  * As above, this is a relation lookup but could be a type lookup if we
1842  * weren't being backwards-compatible about error wording.
1843  */
1844  if (list_length(idents) != 2)
1845  return NULL;
1846 
1847  /* Avoid memory leaks in long-term function context */
1849 
1850  /* Look up relation name. Can't lock it - we might not have privileges. */
1851  relvar = makeRangeVar(strVal(linitial(idents)),
1852  strVal(lsecond(idents)),
1853  -1);
1854  classOid = RangeVarGetRelid(relvar, NoLock, false);
1855 
1856  /* Some relkinds lack type OIDs */
1857  typOid = get_rel_type_id(classOid);
1858  if (!OidIsValid(typOid))
1859  ereport(ERROR,
1860  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1861  errmsg("relation \"%s\" does not have a composite type",
1862  strVal(lsecond(idents)))));
1863 
1864  MemoryContextSwitchTo(oldCxt);
1865 
1866  /* Build and return the row type struct */
1867  return plpgsql_build_datatype(typOid, -1, InvalidOid,
1868  makeTypeNameFromNameList(idents));
1869 }
#define OidIsValid(objectId)
Definition: c.h:711
#define NoLock
Definition: lockdefs.h:34
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1961
TypeName * makeTypeNameFromNameList(List *names)
Definition: makefuncs.c:456
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:422
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
static int list_length(const List *l)
Definition: pg_list.h:150
#define linitial(l)
Definition: pg_list.h:176
#define lsecond(l)
Definition: pg_list.h:181
#define strVal(v)
Definition: value.h:82

References ereport, errcode(), errmsg(), ERROR, get_rel_type_id(), InvalidOid, linitial, list_length(), lsecond, makeRangeVar(), makeTypeNameFromNameList(), MemoryContextSwitchTo(), NoLock, OidIsValid, plpgsql_build_datatype(), plpgsql_compile_tmp_cxt, RangeVarGetRelid, and strVal.

◆ plpgsql_parse_cwordtype()

PLpgSQL_type* plpgsql_parse_cwordtype ( List idents)

Definition at line 1676 of file pl_comp.c.

1677 {
1678  PLpgSQL_type *dtype = NULL;
1679  PLpgSQL_nsitem *nse;
1680  const char *fldname;
1681  Oid classOid;
1682  HeapTuple classtup = NULL;
1683  HeapTuple attrtup = NULL;
1684  HeapTuple typetup = NULL;
1685  Form_pg_class classStruct;
1686  Form_pg_attribute attrStruct;
1687  MemoryContext oldCxt;
1688 
1689  /* Avoid memory leaks in the long-term function context */
1691 
1692  if (list_length(idents) == 2)
1693  {
1694  /*
1695  * Do a lookup in the current namespace stack. We don't need to check
1696  * number of names matched, because we will only consider scalar
1697  * variables.
1698  */
1699  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1700  strVal(linitial(idents)),
1701  strVal(lsecond(idents)),
1702  NULL,
1703  NULL);
1704 
1705  if (nse != NULL && nse->itemtype == PLPGSQL_NSTYPE_VAR)
1706  {
1707  dtype = ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1708  goto done;
1709  }
1710 
1711  /*
1712  * First word could also be a table name
1713  */
1714  classOid = RelnameGetRelid(strVal(linitial(idents)));
1715  if (!OidIsValid(classOid))
1716  goto done;
1717  fldname = strVal(lsecond(idents));
1718  }
1719  else if (list_length(idents) == 3)
1720  {
1721  RangeVar *relvar;
1722 
1723  relvar = makeRangeVar(strVal(linitial(idents)),
1724  strVal(lsecond(idents)),
1725  -1);
1726  /* Can't lock relation - we might not have privileges. */
1727  classOid = RangeVarGetRelid(relvar, NoLock, true);
1728  if (!OidIsValid(classOid))
1729  goto done;
1730  fldname = strVal(lthird(idents));
1731  }
1732  else
1733  goto done;
1734 
1735  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classOid));
1736  if (!HeapTupleIsValid(classtup))
1737  goto done;
1738  classStruct = (Form_pg_class) GETSTRUCT(classtup);
1739 
1740  /*
1741  * It must be a relation, sequence, view, materialized view, composite
1742  * type, or foreign table
1743  */
1744  if (classStruct->relkind != RELKIND_RELATION &&
1745  classStruct->relkind != RELKIND_SEQUENCE &&
1746  classStruct->relkind != RELKIND_VIEW &&
1747  classStruct->relkind != RELKIND_MATVIEW &&
1748  classStruct->relkind != RELKIND_COMPOSITE_TYPE &&
1749  classStruct->relkind != RELKIND_FOREIGN_TABLE &&
1750  classStruct->relkind != RELKIND_PARTITIONED_TABLE)
1751  goto done;
1752 
1753  /*
1754  * Fetch the named table field and its type
1755  */
1756  attrtup = SearchSysCacheAttName(classOid, fldname);
1757  if (!HeapTupleIsValid(attrtup))
1758  goto done;
1759  attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup);
1760 
1761  typetup = SearchSysCache1(TYPEOID,
1762  ObjectIdGetDatum(attrStruct->atttypid));
1763  if (!HeapTupleIsValid(typetup))
1764  elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid);
1765 
1766  /*
1767  * Found that - build a compiler type struct in the caller's cxt and
1768  * return it. Note that we treat the type as being found-by-OID; no
1769  * attempt to re-look-up the type name will happen during invalidations.
1770  */
1771  MemoryContextSwitchTo(oldCxt);
1772  dtype = build_datatype(typetup,
1773  attrStruct->atttypmod,
1774  attrStruct->attcollation,
1775  NULL);
1777 
1778 done:
1779  if (HeapTupleIsValid(classtup))
1780  ReleaseSysCache(classtup);
1781  if (HeapTupleIsValid(attrtup))
1782  ReleaseSysCache(attrtup);
1783  if (HeapTupleIsValid(typetup))
1784  ReleaseSysCache(typetup);
1785 
1786  MemoryContextSwitchTo(oldCxt);
1787  return dtype;
1788 }
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:683
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
#define lthird(l)
Definition: pg_list.h:186
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:81
PLpgSQL_nsitem * plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode, const char *name1, const char *name2, const char *name3, int *names_used)
Definition: pl_funcs.c:130
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1314
@ RELOID
Definition: syscache.h:89

References build_datatype(), elog(), ERROR, GETSTRUCT, HeapTupleIsValid, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, linitial, list_length(), lsecond, lthird, makeRangeVar(), MemoryContextSwitchTo(), NoLock, ObjectIdGetDatum(), OidIsValid, plpgsql_compile_tmp_cxt, plpgsql_Datums, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_VAR, RangeVarGetRelid, ReleaseSysCache(), RelnameGetRelid(), RELOID, SearchSysCache1(), SearchSysCacheAttName(), strVal, and TYPEOID.

◆ plpgsql_parse_dblword()

bool plpgsql_parse_dblword ( char *  word1,
char *  word2,
PLwdatum wdatum,
PLcword cword 
)

Definition at line 1445 of file pl_comp.c.

1447 {
1448  PLpgSQL_nsitem *ns;
1449  List *idents;
1450  int nnames;
1451 
1452  idents = list_make2(makeString(word1),
1453  makeString(word2));
1454 
1455  /*
1456  * We should do nothing in DECLARE sections. In SQL expressions, we
1457  * really only need to make sure that RECFIELD datums are created when
1458  * needed. In all the cases handled by this function, returning a T_DATUM
1459  * with a two-word idents string is the right thing.
1460  */
1462  {
1463  /*
1464  * Do a lookup in the current namespace stack
1465  */
1466  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1467  word1, word2, NULL,
1468  &nnames);
1469  if (ns != NULL)
1470  {
1471  switch (ns->itemtype)
1472  {
1473  case PLPGSQL_NSTYPE_VAR:
1474  /* Block-qualified reference to scalar variable. */
1475  wdatum->datum = plpgsql_Datums[ns->itemno];
1476  wdatum->ident = NULL;
1477  wdatum->quoted = false; /* not used */
1478  wdatum->idents = idents;
1479  return true;
1480 
1481  case PLPGSQL_NSTYPE_REC:
1482  if (nnames == 1)
1483  {
1484  /*
1485  * First word is a record name, so second word could
1486  * be a field in this record. We build a RECFIELD
1487  * datum whether it is or not --- any error will be
1488  * detected later.
1489  */
1490  PLpgSQL_rec *rec;
1491  PLpgSQL_recfield *new;
1492 
1493  rec = (PLpgSQL_rec *) (plpgsql_Datums[ns->itemno]);
1494  new = plpgsql_build_recfield(rec, word2);
1495 
1496  wdatum->datum = (PLpgSQL_datum *) new;
1497  }
1498  else
1499  {
1500  /* Block-qualified reference to record variable. */
1501  wdatum->datum = plpgsql_Datums[ns->itemno];
1502  }
1503  wdatum->ident = NULL;
1504  wdatum->quoted = false; /* not used */
1505  wdatum->idents = idents;
1506  return true;
1507 
1508  default:
1509  break;
1510  }
1511  }
1512  }
1513 
1514  /* Nothing found */
1515  cword->idents = idents;
1516  return false;
1517 }
#define list_make2(x1, x2)
Definition: pg_list.h:212
PLpgSQL_recfield * plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
Definition: pl_comp.c:2038
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:26
Definition: pg_list.h:52
List * idents
Definition: plpgsql.h:1172
List * idents
Definition: plpgsql.h:1180
char * ident
Definition: plpgsql.h:1178
PLpgSQL_datum * datum
Definition: plpgsql.h:1177
bool quoted
Definition: plpgsql.h:1179
String * makeString(char *str)
Definition: value.c:63

References PLwdatum::datum, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make2, makeString(), plpgsql_build_recfield(), plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, and PLwdatum::quoted.

Referenced by plpgsql_yylex().

◆ plpgsql_parse_err_condition()

PLpgSQL_condition* plpgsql_parse_err_condition ( char *  condname)

Definition at line 2259 of file pl_comp.c.

2260 {
2261  int i;
2262  PLpgSQL_condition *new;
2263  PLpgSQL_condition *prev;
2264 
2265  /*
2266  * XXX Eventually we will want to look for user-defined exception names
2267  * here.
2268  */
2269 
2270  /*
2271  * OTHERS is represented as code 0 (which would map to '00000', but we
2272  * have no need to represent that as an exception condition).
2273  */
2274  if (strcmp(condname, "others") == 0)
2275  {
2276  new = palloc(sizeof(PLpgSQL_condition));
2277  new->sqlerrstate = 0;
2278  new->condname = condname;
2279  new->next = NULL;
2280  return new;
2281  }
2282 
2283  prev = NULL;
2284  for (i = 0; exception_label_map[i].label != NULL; i++)
2285  {
2286  if (strcmp(condname, exception_label_map[i].label) == 0)
2287  {
2288  new = palloc(sizeof(PLpgSQL_condition));
2289  new->sqlerrstate = exception_label_map[i].sqlerrstate;
2290  new->condname = condname;
2291  new->next = prev;
2292  prev = new;
2293  }
2294  }
2295 
2296  if (!prev)
2297  ereport(ERROR,
2298  (errcode(ERRCODE_UNDEFINED_OBJECT),
2299  errmsg("unrecognized exception condition \"%s\"",
2300  condname)));
2301 
2302  return prev;
2303 }
static const ExceptionLabelMap exception_label_map[]
Definition: pl_comp.c:82
const char * label
Definition: pl_comp.c:78

References ereport, errcode(), errmsg(), ERROR, exception_label_map, i, label, ExceptionLabelMap::label, palloc(), and ExceptionLabelMap::sqlerrstate.

◆ plpgsql_parse_tripword()

bool plpgsql_parse_tripword ( char *  word1,
char *  word2,
char *  word3,
PLwdatum wdatum,
PLcword cword 
)

Definition at line 1526 of file pl_comp.c.

1528 {
1529  PLpgSQL_nsitem *ns;
1530  List *idents;
1531  int nnames;
1532 
1533  /*
1534  * We should do nothing in DECLARE sections. In SQL expressions, we need
1535  * to make sure that RECFIELD datums are created when needed, and we need
1536  * to be careful about how many names are reported as belonging to the
1537  * T_DATUM: the third word could be a sub-field reference, which we don't
1538  * care about here.
1539  */
1541  {
1542  /*
1543  * Do a lookup in the current namespace stack. Must find a record
1544  * reference, else ignore.
1545  */
1546  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1547  word1, word2, word3,
1548  &nnames);
1549  if (ns != NULL)
1550  {
1551  switch (ns->itemtype)
1552  {
1553  case PLPGSQL_NSTYPE_REC:
1554  {
1555  PLpgSQL_rec *rec;
1556  PLpgSQL_recfield *new;
1557 
1558  rec = (PLpgSQL_rec *) (plpgsql_Datums[ns->itemno]);
1559  if (nnames == 1)
1560  {
1561  /*
1562  * First word is a record name, so second word
1563  * could be a field in this record (and the third,
1564  * a sub-field). We build a RECFIELD datum
1565  * whether it is or not --- any error will be
1566  * detected later.
1567  */
1568  new = plpgsql_build_recfield(rec, word2);
1569  idents = list_make2(makeString(word1),
1570  makeString(word2));
1571  }
1572  else
1573  {
1574  /* Block-qualified reference to record variable. */
1575  new = plpgsql_build_recfield(rec, word3);
1576  idents = list_make3(makeString(word1),
1577  makeString(word2),
1578  makeString(word3));
1579  }
1580  wdatum->datum = (PLpgSQL_datum *) new;
1581  wdatum->ident = NULL;
1582  wdatum->quoted = false; /* not used */
1583  wdatum->idents = idents;
1584  return true;
1585  }
1586 
1587  default:
1588  break;
1589  }
1590  }
1591  }
1592 
1593  /* Nothing found */
1594  idents = list_make3(makeString(word1),
1595  makeString(word2),
1596  makeString(word3));
1597  cword->idents = idents;
1598  return false;
1599 }
#define list_make3(x1, x2, x3)
Definition: pg_list.h:214

References PLwdatum::datum, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make2, list_make3, makeString(), plpgsql_build_recfield(), plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, and PLwdatum::quoted.

Referenced by plpgsql_yylex().

◆ plpgsql_parse_word()

bool plpgsql_parse_word ( char *  word1,
const char *  yytxt,
bool  lookup,
PLwdatum wdatum,
PLword word 
)

Definition at line 1390 of file pl_comp.c.

1392 {
1393  PLpgSQL_nsitem *ns;
1394 
1395  /*
1396  * We should not lookup variables in DECLARE sections. In SQL
1397  * expressions, there's no need to do so either --- lookup will happen
1398  * when the expression is compiled.
1399  */
1401  {
1402  /*
1403  * Do a lookup in the current namespace stack
1404  */
1405  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1406  word1, NULL, NULL,
1407  NULL);
1408 
1409  if (ns != NULL)
1410  {
1411  switch (ns->itemtype)
1412  {
1413  case PLPGSQL_NSTYPE_VAR:
1414  case PLPGSQL_NSTYPE_REC:
1415  wdatum->datum = plpgsql_Datums[ns->itemno];
1416  wdatum->ident = word1;
1417  wdatum->quoted = (yytxt[0] == '"');
1418  wdatum->idents = NIL;
1419  return true;
1420 
1421  default:
1422  /* plpgsql_ns_lookup should never return anything else */
1423  elog(ERROR, "unrecognized plpgsql itemtype: %d",
1424  ns->itemtype);
1425  }
1426  }
1427  }
1428 
1429  /*
1430  * Nothing found - up to now it's a word without any special meaning for
1431  * us.
1432  */
1433  word->ident = word1;
1434  word->quoted = (yytxt[0] == '"');
1435  return false;
1436 }
#define NIL
Definition: pg_list.h:66
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition: regcomp.c:1476
Definition: zic.c:304

References PLwdatum::datum, elog(), ERROR, PLwdatum::ident, IDENTIFIER_LOOKUP_NORMAL, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, NIL, plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, PLwdatum::quoted, and word().

Referenced by plpgsql_yylex().

◆ plpgsql_parse_wordrowtype()

PLpgSQL_type* plpgsql_parse_wordrowtype ( char *  ident)

Definition at line 1796 of file pl_comp.c.

1797 {
1798  Oid classOid;
1799  Oid typOid;
1800 
1801  /*
1802  * Look up the relation. Note that because relation rowtypes have the
1803  * same names as their relations, this could be handled as a type lookup
1804  * equally well; we use the relation lookup code path only because the
1805  * errors thrown here have traditionally referred to relations not types.
1806  * But we'll make a TypeName in case we have to do re-look-up of the type.
1807  */
1808  classOid = RelnameGetRelid(ident);
1809  if (!OidIsValid(classOid))
1810  ereport(ERROR,
1812  errmsg("relation \"%s\" does not exist", ident)));
1813 
1814  /* Some relkinds lack type OIDs */
1815  typOid = get_rel_type_id(classOid);
1816  if (!OidIsValid(typOid))
1817  ereport(ERROR,
1818  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1819  errmsg("relation \"%s\" does not have a composite type",
1820  ident)));
1821 
1822  /* Build and return the row type struct */
1823  return plpgsql_build_datatype(typOid, -1, InvalidOid,
1824  makeTypeName(ident));
1825 }
TypeName * makeTypeName(char *typnam)
Definition: makefuncs.c:444
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:77

References ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, get_rel_type_id(), InvalidOid, makeTypeName(), OidIsValid, plpgsql_build_datatype(), and RelnameGetRelid().

◆ plpgsql_parse_wordtype()

PLpgSQL_type* plpgsql_parse_wordtype ( char *  ident)

Definition at line 1610 of file pl_comp.c.

1611 {
1612  PLpgSQL_type *dtype;
1613  PLpgSQL_nsitem *nse;
1614  TypeName *typeName;
1615  HeapTuple typeTup;
1616 
1617  /*
1618  * Do a lookup in the current namespace stack
1619  */
1620  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1621  ident, NULL, NULL,
1622  NULL);
1623 
1624  if (nse != NULL)
1625  {
1626  switch (nse->itemtype)
1627  {
1628  case PLPGSQL_NSTYPE_VAR:
1629  return ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1630 
1631  /* XXX perhaps allow REC/ROW here? */
1632 
1633  default:
1634  return NULL;
1635  }
1636  }
1637 
1638  /*
1639  * Word wasn't found in the namespace stack. Try to find a data type with
1640  * that name, but ignore shell types and complex types.
1641  */
1642  typeName = makeTypeName(ident);
1643  typeTup = LookupTypeName(NULL, typeName, NULL, false);
1644  if (typeTup)
1645  {
1646  Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
1647 
1648  if (!typeStruct->typisdefined ||
1649  typeStruct->typrelid != InvalidOid)
1650  {
1651  ReleaseSysCache(typeTup);
1652  return NULL;
1653  }
1654 
1655  dtype = build_datatype(typeTup, -1,
1657  typeName);
1658 
1659  ReleaseSysCache(typeTup);
1660  return dtype;
1661  }
1662 
1663  /*
1664  * Nothing found - up to now it's a word without any special meaning for
1665  * us.
1666  */
1667  return NULL;
1668 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
Oid fn_input_collation
Definition: plpgsql.h:972

References build_datatype(), PLpgSQL_function::fn_input_collation, GETSTRUCT, InvalidOid, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, LookupTypeName(), makeTypeName(), plpgsql_curr_compile, plpgsql_Datums, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_VAR, and ReleaseSysCache().

◆ plpgsql_parser_setup()

PGDLLEXPORT void plpgsql_parser_setup ( struct ParseState pstate,
PLpgSQL_expr expr 
)

Definition at line 1081 of file pl_comp.c.

1082 {
1086  /* no need to use p_coerce_param_hook */
1087  pstate->p_ref_hook_state = (void *) expr;
1088 }
static Node * plpgsql_param_ref(ParseState *pstate, ParamRef *pref)
Definition: pl_comp.c:1152
static Node * plpgsql_pre_column_ref(ParseState *pstate, ColumnRef *cref)
Definition: pl_comp.c:1094
static Node * plpgsql_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var)
Definition: pl_comp.c:1108
void * p_ref_hook_state
Definition: parse_node.h:230
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:228
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:226
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:227

References ParseState::p_paramref_hook, ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseState::p_ref_hook_state, plpgsql_param_ref(), plpgsql_post_column_ref(), and plpgsql_pre_column_ref().

Referenced by exec_prepare_plan(), and plpgsql_estate_setup().

◆ plpgsql_peek()

int plpgsql_peek ( void  )

Definition at line 420 of file pl_scanner.c.

421 {
422  int tok1;
423  TokenAuxData aux1;
424 
425  tok1 = internal_yylex(&aux1);
426  push_back_token(tok1, &aux1);
427  return tok1;
428 }
static void push_back_token(int token, TokenAuxData *auxdata)
Definition: pl_scanner.c:354
static int internal_yylex(TokenAuxData *auxdata)
Definition: pl_scanner.c:308

References internal_yylex(), and push_back_token().

◆ plpgsql_peek2()

void plpgsql_peek2 ( int *  tok1_p,
int *  tok2_p,
int *  tok1_loc,
int *  tok2_loc 
)

Definition at line 439 of file pl_scanner.c.

440 {
441  int tok1,
442  tok2;
443  TokenAuxData aux1,
444  aux2;
445 
446  tok1 = internal_yylex(&aux1);
447  tok2 = internal_yylex(&aux2);
448 
449  *tok1_p = tok1;
450  if (tok1_loc)
451  *tok1_loc = aux1.lloc;
452  *tok2_p = tok2;
453  if (tok2_loc)
454  *tok2_loc = aux2.lloc;
455 
456  push_back_token(tok2, &aux2);
457  push_back_token(tok1, &aux1);
458 }
YYLTYPE lloc
Definition: pl_scanner.c:94

References internal_yylex(), TokenAuxData::lloc, and push_back_token().

◆ plpgsql_push_back_token()

void plpgsql_push_back_token ( int  token)

Definition at line 370 of file pl_scanner.c.

371 {
372  TokenAuxData auxdata;
373 
374  auxdata.lval = plpgsql_yylval;
375  auxdata.lloc = plpgsql_yylloc;
376  auxdata.leng = plpgsql_yyleng;
377  push_back_token(token, &auxdata);
378 }
static int plpgsql_yyleng
Definition: pl_scanner.c:113
YYSTYPE lval
Definition: pl_scanner.c:93

References TokenAuxData::leng, TokenAuxData::lloc, TokenAuxData::lval, plpgsql_yyleng, and push_back_token().

◆ plpgsql_recognize_err_condition()

PGDLLEXPORT int plpgsql_recognize_err_condition ( const char *  condname,
bool  allow_sqlstate 
)

Definition at line 2223 of file pl_comp.c.

2224 {
2225  int i;
2226 
2227  if (allow_sqlstate)
2228  {
2229  if (strlen(condname) == 5 &&
2230  strspn(condname, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
2231  return MAKE_SQLSTATE(condname[0],
2232  condname[1],
2233  condname[2],
2234  condname[3],
2235  condname[4]);
2236  }
2237 
2238  for (i = 0; exception_label_map[i].label != NULL; i++)
2239  {
2240  if (strcmp(condname, exception_label_map[i].label) == 0)
2242  }
2243 
2244  ereport(ERROR,
2245  (errcode(ERRCODE_UNDEFINED_OBJECT),
2246  errmsg("unrecognized exception condition \"%s\"",
2247  condname)));
2248  return 0; /* keep compiler quiet */
2249 }
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:52

References ereport, errcode(), errmsg(), ERROR, exception_label_map, i, label, ExceptionLabelMap::label, MAKE_SQLSTATE, and ExceptionLabelMap::sqlerrstate.

Referenced by exec_stmt_raise().

◆ plpgsql_scanner_errposition()

int plpgsql_scanner_errposition ( int  location)

Definition at line 472 of file pl_scanner.c.

473 {
474  int pos;
475 
476  if (location < 0 || scanorig == NULL)
477  return 0; /* no-op if location is unknown */
478 
479  /* Convert byte offset to character number */
480  pos = pg_mbstrlen_with_len(scanorig, location) + 1;
481  /* And pass it to the ereport mechanism */
482  (void) internalerrposition(pos);
483  /* Also pass the function body string */
484  return internalerrquery(scanorig);
485 }
int internalerrquery(const char *query)
Definition: elog.c:1358
int internalerrposition(int cursorpos)
Definition: elog.c:1338
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1000

References internalerrposition(), internalerrquery(), pg_mbstrlen_with_len(), and scanorig.

Referenced by plpgsql_yyerror().

◆ plpgsql_scanner_finish()

void plpgsql_scanner_finish ( void  )

Definition at line 613 of file pl_scanner.c.

614 {
615  /* release storage */
617  /* avoid leaving any dangling pointers */
618  yyscanner = NULL;
619  scanorig = NULL;
620 }
static core_yyscan_t yyscanner
Definition: pl_scanner.c:106
void scanner_finish(core_yyscan_t yyscanner)

References scanner_finish(), scanorig, and yyscanner.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_scanner_init()

void plpgsql_scanner_init ( const char *  str)

Definition at line 586 of file pl_scanner.c.

587 {
588  /* Start up the core scanner */
590  &ReservedPLKeywords, ReservedPLKeywordTokens);
591 
592  /*
593  * scanorig points to the original string, which unlike the scanner's
594  * scanbuf won't be modified on-the-fly by flex. Notice that although
595  * yytext points into scanbuf, we rely on being able to apply locations
596  * (offsets from string start) to scanorig as well.
597  */
598  scanorig = str;
599 
600  /* Other setup */
602  plpgsql_yytoken = 0;
603 
604  num_pushbacks = 0;
605 
607 }
static int num_pushbacks
Definition: pl_scanner.c:121
static int plpgsql_yytoken
Definition: pl_scanner.c:116
static const uint16 ReservedPLKeywordTokens[]
Definition: pl_scanner.c:66
static core_yy_extra_type core_yy
Definition: pl_scanner.c:107
core_yyscan_t scanner_init(const char *str, core_yy_extra_type *yyext, const ScanKeywordList *keywordlist, const uint16 *keyword_tokens)

References core_yy, IDENTIFIER_LOOKUP_NORMAL, location_lineno_init(), num_pushbacks, plpgsql_IdentifierLookup, plpgsql_yytoken, ReservedPLKeywordTokens, scanner_init(), scanorig, generate_unaccent_rules::str, and yyscanner.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_stmt_typename()

PGDLLEXPORT const char* plpgsql_stmt_typename ( PLpgSQL_stmt stmt)

Definition at line 232 of file pl_funcs.c.

233 {
234  switch (stmt->cmd_type)
235  {
236  case PLPGSQL_STMT_BLOCK:
237  return _("statement block");
238  case PLPGSQL_STMT_ASSIGN:
239  return _("assignment");
240  case PLPGSQL_STMT_IF:
241  return "IF";
242  case PLPGSQL_STMT_CASE:
243  return "CASE";
244  case PLPGSQL_STMT_LOOP:
245  return "LOOP";
246  case PLPGSQL_STMT_WHILE:
247  return "WHILE";
248  case PLPGSQL_STMT_FORI:
249  return _("FOR with integer loop variable");
250  case PLPGSQL_STMT_FORS:
251  return _("FOR over SELECT rows");
252  case PLPGSQL_STMT_FORC:
253  return _("FOR over cursor");
255  return _("FOREACH over array");
256  case PLPGSQL_STMT_EXIT:
257  return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
258  case PLPGSQL_STMT_RETURN:
259  return "RETURN";
261  return "RETURN NEXT";
263  return "RETURN QUERY";
264  case PLPGSQL_STMT_RAISE:
265  return "RAISE";
266  case PLPGSQL_STMT_ASSERT:
267  return "ASSERT";
269  return _("SQL statement");
271  return "EXECUTE";
273  return _("FOR over EXECUTE statement");
275  return ((PLpgSQL_stmt_getdiag *) stmt)->is_stacked ?
276  "GET STACKED DIAGNOSTICS" : "GET DIAGNOSTICS";
277  case PLPGSQL_STMT_OPEN:
278  return "OPEN";
279  case PLPGSQL_STMT_FETCH:
280  return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
281  case PLPGSQL_STMT_CLOSE:
282  return "CLOSE";
284  return "PERFORM";
285  case PLPGSQL_STMT_CALL:
286  return ((PLpgSQL_stmt_call *) stmt)->is_call ? "CALL" : "DO";
287  case PLPGSQL_STMT_COMMIT:
288  return "COMMIT";
290  return "ROLLBACK";
291  }
292 
293  return "unknown";
294 }
#define _(x)
Definition: elog.c:90
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:454

References _, PLpgSQL_stmt::cmd_type, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CALL, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, and PLPGSQL_STMT_WHILE.

Referenced by plpgsql_exec_error_callback().

◆ plpgsql_subxact_cb()

void plpgsql_subxact_cb ( SubXactEvent  event,
SubTransactionId  mySubid,
SubTransactionId  parentSubid,
void *  arg 
)

Definition at line 8454 of file pl_exec.c.

8456 {
8457  if (event == SUBXACT_EVENT_COMMIT_SUB || event == SUBXACT_EVENT_ABORT_SUB)
8458  {
8459  while (simple_econtext_stack != NULL &&
8460  simple_econtext_stack->xact_subxid == mySubid)
8461  {
8463 
8465  (event == SUBXACT_EVENT_COMMIT_SUB));
8469  }
8470  }
8471 }
static int32 next
Definition: blutils.c:219
void FreeExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:415
void pfree(void *pointer)
Definition: mcxt.c:1306
static SimpleEcontextStackEntry * simple_econtext_stack
Definition: pl_exec.c:96
struct SimpleEcontextStackEntry * next
Definition: pl_exec.c:92
ExprContext * stack_econtext
Definition: pl_exec.c:90
SubTransactionId xact_subxid
Definition: pl_exec.c:91
@ SUBXACT_EVENT_ABORT_SUB
Definition: xact.h:137
@ SUBXACT_EVENT_COMMIT_SUB
Definition: xact.h:136

References FreeExprContext(), next, SimpleEcontextStackEntry::next, pfree(), simple_econtext_stack, SimpleEcontextStackEntry::stack_econtext, SUBXACT_EVENT_ABORT_SUB, SUBXACT_EVENT_COMMIT_SUB, and SimpleEcontextStackEntry::xact_subxid.

Referenced by _PG_init(), and plpgsql_inline_handler().

◆ plpgsql_token_is_unreserved_keyword()

bool plpgsql_token_is_unreserved_keyword ( int  token)

Definition at line 387 of file pl_scanner.c.

388 {
389  int i;
390 
391  for (i = 0; i < lengthof(UnreservedPLKeywordTokens); i++)
392  {
393  if (UnreservedPLKeywordTokens[i] == token)
394  return true;
395  }
396  return false;
397 }
#define lengthof(array)
Definition: c.h:724
static const uint16 UnreservedPLKeywordTokens[]
Definition: pl_scanner.c:70

References i, lengthof, and UnreservedPLKeywordTokens.

◆ plpgsql_xact_cb()

void plpgsql_xact_cb ( XactEvent  event,
void *  arg 
)

Definition at line 8412 of file pl_exec.c.

8413 {
8414  /*
8415  * If we are doing a clean transaction shutdown, free the EState and tell
8416  * the resowner to release whatever plancache references it has, so that
8417  * all remaining resources will be released correctly. (We don't need to
8418  * actually delete the resowner here; deletion of the
8419  * TopTransactionResourceOwner will take care of that.)
8420  *
8421  * In an abort, we expect the regular abort recovery procedures to release
8422  * everything of interest, so just clear our pointers.
8423  */
8424  if (event == XACT_EVENT_COMMIT ||
8425  event == XACT_EVENT_PARALLEL_COMMIT ||
8426  event == XACT_EVENT_PREPARE)
8427  {
8428  simple_econtext_stack = NULL;
8429 
8436  }
8437  else if (event == XACT_EVENT_ABORT ||
8438  event == XACT_EVENT_PARALLEL_ABORT)
8439  {
8440  simple_econtext_stack = NULL;
8443  }
8444 }
void FreeExecutorState(EState *estate)
Definition: execUtils.c:190
static ResourceOwner shared_simple_eval_resowner
Definition: pl_exec.c:106
static EState * shared_simple_eval_estate
Definition: pl_exec.c:95
void ResourceOwnerReleaseAllPlanCacheRefs(ResourceOwner owner)
Definition: resowner.c:723
@ XACT_EVENT_COMMIT
Definition: xact.h:121
@ XACT_EVENT_PARALLEL_COMMIT
Definition: xact.h:122
@ XACT_EVENT_ABORT
Definition: xact.h:123
@ XACT_EVENT_PARALLEL_ABORT
Definition: xact.h:124
@ XACT_EVENT_PREPARE
Definition: xact.h:125

References FreeExecutorState(), ResourceOwnerReleaseAllPlanCacheRefs(), shared_simple_eval_estate, shared_simple_eval_resowner, simple_econtext_stack, XACT_EVENT_ABORT, XACT_EVENT_COMMIT, XACT_EVENT_PARALLEL_ABORT, XACT_EVENT_PARALLEL_COMMIT, and XACT_EVENT_PREPARE.

Referenced by _PG_init().

◆ plpgsql_yyerror()

void plpgsql_yyerror ( const char *  message)

Definition at line 499 of file pl_scanner.c.

500 {
501  char *yytext = core_yy.scanbuf + plpgsql_yylloc;
502 
503  if (*yytext == '\0')
504  {
505  ereport(ERROR,
506  (errcode(ERRCODE_SYNTAX_ERROR),
507  /* translator: %s is typically the translation of "syntax error" */
508  errmsg("%s at end of input", _(message)),
509  plpgsql_scanner_errposition(plpgsql_yylloc)));
510  }
511  else
512  {
513  /*
514  * If we have done any lookahead then flex will have restored the
515  * character after the end-of-token. Zap it again so that we report
516  * only the single token here. This modifies scanbuf but we no longer
517  * care about that.
518  */
519  yytext[plpgsql_yyleng] = '\0';
520 
521  ereport(ERROR,
522  (errcode(ERRCODE_SYNTAX_ERROR),
523  /* translator: first %s is typically the translation of "syntax error" */
524  errmsg("%s at or near \"%s\"", _(message), yytext),
525  plpgsql_scanner_errposition(plpgsql_yylloc)));
526  }
527 }
int plpgsql_scanner_errposition(int location)
Definition: pl_scanner.c:472
char * scanbuf
Definition: scanner.h:72

References _, core_yy, ereport, errcode(), errmsg(), ERROR, plpgsql_scanner_errposition(), plpgsql_yyleng, and core_yy_extra_type::scanbuf.

◆ plpgsql_yylex()

int plpgsql_yylex ( void  )

Definition at line 146 of file pl_scanner.c.

147 {
148  int tok1;
149  TokenAuxData aux1;
150  int kwnum;
151 
152  tok1 = internal_yylex(&aux1);
153  if (tok1 == IDENT || tok1 == PARAM)
154  {
155  int tok2;
156  TokenAuxData aux2;
157 
158  tok2 = internal_yylex(&aux2);
159  if (tok2 == '.')
160  {
161  int tok3;
162  TokenAuxData aux3;
163 
164  tok3 = internal_yylex(&aux3);
165  if (tok3 == IDENT)
166  {
167  int tok4;
168  TokenAuxData aux4;
169 
170  tok4 = internal_yylex(&aux4);
171  if (tok4 == '.')
172  {
173  int tok5;
174  TokenAuxData aux5;
175 
176  tok5 = internal_yylex(&aux5);
177  if (tok5 == IDENT)
178  {
179  if (plpgsql_parse_tripword(aux1.lval.str,
180  aux3.lval.str,
181  aux5.lval.str,
182  &aux1.lval.wdatum,
183  &aux1.lval.cword))
184  tok1 = T_DATUM;
185  else
186  tok1 = T_CWORD;
187  }
188  else
189  {
190  /* not A.B.C, so just process A.B */
191  push_back_token(tok5, &aux5);
192  push_back_token(tok4, &aux4);
193  if (plpgsql_parse_dblword(aux1.lval.str,
194  aux3.lval.str,
195  &aux1.lval.wdatum,
196  &aux1.lval.cword))
197  tok1 = T_DATUM;
198  else
199  tok1 = T_CWORD;
200  }
201  }
202  else
203  {
204  /* not A.B.C, so just process A.B */
205  push_back_token(tok4, &aux4);
206  if (plpgsql_parse_dblword(aux1.lval.str,
207  aux3.lval.str,
208  &aux1.lval.wdatum,
209  &aux1.lval.cword))
210  tok1 = T_DATUM;
211  else
212  tok1 = T_CWORD;
213  }
214  }
215  else
216  {
217  /* not A.B, so just process A */
218  push_back_token(tok3, &aux3);
219  push_back_token(tok2, &aux2);
220  if (plpgsql_parse_word(aux1.lval.str,
221  core_yy.scanbuf + aux1.lloc,
222  true,
223  &aux1.lval.wdatum,
224  &aux1.lval.word))
225  tok1 = T_DATUM;
226  else if (!aux1.lval.word.quoted &&
227  (kwnum = ScanKeywordLookup(aux1.lval.word.ident,
228  &UnreservedPLKeywords)) >= 0)
229  {
230  aux1.lval.keyword = GetScanKeyword(kwnum,
231  &UnreservedPLKeywords);
232  tok1 = UnreservedPLKeywordTokens[kwnum];
233  }
234  else
235  tok1 = T_WORD;
236  }
237  }
238  else
239  {
240  /* not A.B, so just process A */
241  push_back_token(tok2, &aux2);
242 
243  /*
244  * See if it matches a variable name, except in the context where
245  * we are at start of statement and the next token isn't
246  * assignment or '['. In that case, it couldn't validly be a
247  * variable name, and skipping the lookup allows variable names to
248  * be used that would conflict with plpgsql or core keywords that
249  * introduce statements (e.g., "comment"). Without this special
250  * logic, every statement-introducing keyword would effectively be
251  * reserved in PL/pgSQL, which would be unpleasant.
252  *
253  * If it isn't a variable name, try to match against unreserved
254  * plpgsql keywords. If not one of those either, it's T_WORD.
255  *
256  * Note: we must call plpgsql_parse_word even if we don't want to
257  * do variable lookup, because it sets up aux1.lval.word for the
258  * non-variable cases.
259  */
260  if (plpgsql_parse_word(aux1.lval.str,
261  core_yy.scanbuf + aux1.lloc,
263  (tok2 == '=' || tok2 == COLON_EQUALS ||
264  tok2 == '[')),
265  &aux1.lval.wdatum,
266  &aux1.lval.word))
267  tok1 = T_DATUM;
268  else if (!aux1.lval.word.quoted &&
269  (kwnum = ScanKeywordLookup(aux1.lval.word.ident,
270  &UnreservedPLKeywords)) >= 0)
271  {
272  aux1.lval.keyword = GetScanKeyword(kwnum,
273  &UnreservedPLKeywords);
274  tok1 = UnreservedPLKeywordTokens[kwnum];
275  }
276  else
277  tok1 = T_WORD;
278  }
279  }
280  else
281  {
282  /*
283  * Not a potential plpgsql variable name, just return the data.
284  *
285  * Note that we also come through here if the grammar pushed back a
286  * T_DATUM, T_CWORD, T_WORD, or unreserved-keyword token returned by a
287  * previous lookup cycle; thus, pushbacks do not incur extra lookup
288  * work, since we'll never do the above code twice for the same token.
289  * This property also makes it safe to rely on the old value of
290  * plpgsql_yytoken in the is-this-start-of-statement test above.
291  */
292  }
293 
294  plpgsql_yylval = aux1.lval;
295  plpgsql_yylloc = aux1.lloc;
296  plpgsql_yyleng = aux1.leng;
297  plpgsql_yytoken = tok1;
298  return tok1;
299 }
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
Definition: kwlookup.c:38
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)
Definition: kwlookup.h:39
bool plpgsql_parse_dblword(char *word1, char *word2, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1445
bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup, PLwdatum *wdatum, PLword *word)
Definition: pl_comp.c:1390
bool plpgsql_parse_tripword(char *word1, char *word2, char *word3, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1526
#define AT_STMT_START(prev_token)
Definition: pl_scanner.c:82

References AT_STMT_START, core_yy, GetScanKeyword(), internal_yylex(), TokenAuxData::leng, TokenAuxData::lloc, TokenAuxData::lval, plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_yyleng, plpgsql_yytoken, push_back_token(), core_yy_extra_type::scanbuf, ScanKeywordLookup(), and UnreservedPLKeywordTokens.

◆ plpgsql_yyparse()

int plpgsql_yyparse ( void  )

Variable Documentation

◆ plpgsql_check_asserts

bool plpgsql_check_asserts
extern

Definition at line 48 of file pl_handler.c.

Referenced by _PG_init(), and exec_stmt_assert().

◆ plpgsql_check_syntax

bool plpgsql_check_syntax
extern

Definition at line 51 of file pl_comp.c.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_compile_tmp_cxt

MemoryContext plpgsql_compile_tmp_cxt
extern

◆ plpgsql_curr_compile

PLpgSQL_function* plpgsql_curr_compile
extern

Definition at line 53 of file pl_comp.c.

Referenced by do_compile(), plpgsql_compile_inline(), and plpgsql_parse_wordtype().

◆ plpgsql_Datums

◆ plpgsql_DumpExecTree

bool plpgsql_DumpExecTree
extern

Definition at line 50 of file pl_comp.c.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_error_funcname

char* plpgsql_error_funcname
extern

Definition at line 49 of file pl_comp.c.

Referenced by do_compile(), plpgsql_compile_error_callback(), and plpgsql_compile_inline().

◆ plpgsql_extra_errors

int plpgsql_extra_errors
extern

◆ plpgsql_extra_warnings

int plpgsql_extra_warnings
extern

◆ plpgsql_IdentifierLookup

IdentifierLookup plpgsql_IdentifierLookup
extern

◆ plpgsql_nDatums

int plpgsql_nDatums
extern

◆ plpgsql_parse_result

PLpgSQL_stmt_block* plpgsql_parse_result
extern

Definition at line 42 of file pl_comp.c.

Referenced by do_compile(), and plpgsql_compile_inline().

◆ plpgsql_plugin_ptr

◆ plpgsql_print_strict_params

bool plpgsql_print_strict_params
extern

Definition at line 46 of file pl_handler.c.

Referenced by _PG_init(), do_compile(), and plpgsql_compile_inline().

◆ plpgsql_variable_conflict

int plpgsql_variable_conflict
extern

Definition at line 44 of file pl_handler.c.

Referenced by _PG_init(), do_compile(), and plpgsql_compile_inline().