PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plpgsql.h File Reference
#include "access/xact.h"
#include "commands/event_trigger.h"
#include "commands/trigger.h"
#include "executor/spi.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_datum
 
struct  PLpgSQL_variable
 
struct  PLpgSQL_expr
 
struct  PLpgSQL_var
 
struct  PLpgSQL_row
 
struct  PLpgSQL_rec
 
struct  PLpgSQL_recfield
 
struct  PLpgSQL_arrayelem
 
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_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
 
#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_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_datum PLpgSQL_datum
 
typedef struct PLpgSQL_variable PLpgSQL_variable
 
typedef struct PLpgSQL_expr PLpgSQL_expr
 
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_arrayelem PLpgSQL_arrayelem
 
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_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_ROW, 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_ARRAYELEM, PLPGSQL_DTYPE_EXPR
}
 
enum  PLpgSQL_type_type { PLPGSQL_TTYPE_SCALAR, PLPGSQL_TTYPE_ROW, 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
}
 
enum  { PLPGSQL_RC_OK, PLPGSQL_RC_EXIT, PLPGSQL_RC_RETURN, PLPGSQL_RC_CONTINUE }
 
enum  PLpgSQL_getdiag_kind {
  PLPGSQL_GETDIAG_ROW_COUNT, PLPGSQL_GETDIAG_RESULT_OID, 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

PLpgSQL_functionplpgsql_compile (FunctionCallInfo fcinfo, bool forValidator)
 
PLpgSQL_functionplpgsql_compile_inline (char *proc_source)
 
void plpgsql_parser_setup (struct ParseState *pstate, PLpgSQL_expr *expr)
 
bool plpgsql_parse_word (char *word1, const char *yytxt, 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)
 
PLpgSQL_typeplpgsql_build_datatype (Oid typeOid, int32 typmod, Oid collation)
 
PLpgSQL_variableplpgsql_build_variable (const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
 
PLpgSQL_recplpgsql_build_record (const char *refname, int lineno, bool add2namespace)
 
int plpgsql_recognize_err_condition (const char *condname, bool allow_sqlstate)
 
PLpgSQL_conditionplpgsql_parse_err_condition (char *condname)
 
void plpgsql_adddatum (PLpgSQL_datum *new)
 
int plpgsql_add_initdatums (int **varnos)
 
void plpgsql_HashTableInit (void)
 
void _PG_init (void)
 
Datum plpgsql_exec_function (PLpgSQL_function *func, FunctionCallInfo fcinfo, EState *simple_eval_estate)
 
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)
 
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)
 
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)
 
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 33 of file plpgsql.h.

#define PLPGSQL_XCHECK_ALL   ((int) ~0)

Definition at line 1028 of file plpgsql.h.

Referenced by plpgsql_extra_checks_check_hook().

#define PLPGSQL_XCHECK_NONE   0

Definition at line 1026 of file plpgsql.h.

Referenced by plpgsql_extra_checks_check_hook().

#define PLPGSQL_XCHECK_SHADOWVAR   1

Definition at line 1027 of file plpgsql.h.

Referenced by plpgsql_extra_checks_check_hook().

#define TEXTDOMAIN   PG_TEXTDOMAIN("plpgsql")

Definition at line 30 of file plpgsql.h.

Typedef Documentation

Enumeration Type Documentation

anonymous enum
Enumerator
PLPGSQL_RC_OK 
PLPGSQL_RC_EXIT 
PLPGSQL_RC_RETURN 
PLPGSQL_RC_CONTINUE 

Definition at line 114 of file plpgsql.h.

Enumerator
IDENTIFIER_LOOKUP_NORMAL 
IDENTIFIER_LOOKUP_DECLARE 
IDENTIFIER_LOOKUP_EXPR 

Definition at line 1010 of file plpgsql.h.

1011 {
1012  IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
1013  IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
1014  IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
IdentifierLookup
Definition: plpgsql.h:1010
Enumerator
PLPGSQL_DTYPE_VAR 
PLPGSQL_DTYPE_ROW 
PLPGSQL_DTYPE_REC 
PLPGSQL_DTYPE_RECFIELD 
PLPGSQL_DTYPE_ARRAYELEM 
PLPGSQL_DTYPE_EXPR 

Definition at line 59 of file plpgsql.h.

Enumerator
PLPGSQL_GETDIAG_ROW_COUNT 
PLPGSQL_GETDIAG_RESULT_OID 
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 125 of file plpgsql.h.

Enumerator
PLPGSQL_LABEL_BLOCK 
PLPGSQL_LABEL_LOOP 
PLPGSQL_LABEL_OTHER 

Definition at line 49 of file plpgsql.h.

50 {
51  PLPGSQL_LABEL_BLOCK, /* DECLARE/BEGIN block */
52  PLPGSQL_LABEL_LOOP, /* looping construct */
53  PLPGSQL_LABEL_OTHER /* anything else */
PLpgSQL_label_type
Definition: plpgsql.h:49
Enumerator
PLPGSQL_NSTYPE_LABEL 
PLPGSQL_NSTYPE_VAR 
PLPGSQL_NSTYPE_ROW 
PLPGSQL_NSTYPE_REC 

Definition at line 38 of file plpgsql.h.

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 145 of file plpgsql.h.

Enumerator
PLPGSQL_RESOLVE_ERROR 
PLPGSQL_RESOLVE_VARIABLE 
PLPGSQL_RESOLVE_COLUMN 

Definition at line 161 of file plpgsql.h.

162 {
163  PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
164  PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
165  PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */
PLpgSQL_resolve_option
Definition: plpgsql.h:161
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 

Definition at line 83 of file plpgsql.h.

84 {
PLpgSQL_stmt_type
Definition: plpgsql.h:83
Enumerator
PLPGSQL_DML_TRIGGER 
PLPGSQL_EVENT_TRIGGER 
PLPGSQL_NOT_TRIGGER 

Definition at line 808 of file plpgsql.h.

Enumerator
PLPGSQL_TTYPE_SCALAR 
PLPGSQL_TTYPE_ROW 
PLPGSQL_TTYPE_REC 
PLPGSQL_TTYPE_PSEUDO 

Definition at line 72 of file plpgsql.h.

73 {
74  PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
75  PLPGSQL_TTYPE_ROW, /* composite types */
76  PLPGSQL_TTYPE_REC, /* RECORD pseudotype */
77  PLPGSQL_TTYPE_PSEUDO /* other pseudotypes */
PLpgSQL_type_type
Definition: plpgsql.h:72

Function Documentation

void _PG_init ( void  )

Definition at line 56 of file auth_delay.c.

57 {
58  /* Define custom GUC variables */
59  DefineCustomIntVariable("auth_delay.milliseconds",
60  "Milliseconds to delay before reporting authentication failure",
61  NULL,
63  0,
64  0, INT_MAX / 1000,
65  PGC_SIGHUP,
67  NULL,
68  NULL,
69  NULL);
70  /* Install Hooks */
73 }
void DefineCustomIntVariable(const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:7765
ClientAuthentication_hook_type ClientAuthentication_hook
Definition: auth.c:235
static ClientAuthentication_hook_type original_client_auth_hook
Definition: auth_delay.c:29
Definition: guc.h:72
static void auth_delay_checks(Port *port, int status)
Definition: auth_delay.c:35
static int auth_delay_milliseconds
Definition: auth_delay.c:26
#define GUC_UNIT_MS
Definition: guc.h:225
int plpgsql_add_initdatums ( int **  varnos)

Definition at line 2396 of file pl_comp.c.

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

2397 {
2398  int i;
2399  int n = 0;
2400 
2401  for (i = datums_last; i < plpgsql_nDatums; i++)
2402  {
2403  switch (plpgsql_Datums[i]->dtype)
2404  {
2405  case PLPGSQL_DTYPE_VAR:
2406  n++;
2407  break;
2408 
2409  default:
2410  break;
2411  }
2412  }
2413 
2414  if (varnos != NULL)
2415  {
2416  if (n > 0)
2417  {
2418  *varnos = (int *) palloc(sizeof(int) * n);
2419 
2420  n = 0;
2421  for (i = datums_last; i < plpgsql_nDatums; i++)
2422  {
2423  switch (plpgsql_Datums[i]->dtype)
2424  {
2425  case PLPGSQL_DTYPE_VAR:
2426  (*varnos)[n++] = plpgsql_Datums[i]->dno;
2427 
2428  default:
2429  break;
2430  }
2431  }
2432  }
2433  else
2434  *varnos = NULL;
2435  }
2436 
2438  return n;
2439 }
int plpgsql_nDatums
Definition: pl_comp.c:46
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
void * palloc(Size size)
Definition: mcxt.c:848
int i
static int datums_last
Definition: pl_comp.c:48
void plpgsql_adddatum ( PLpgSQL_datum new)

Definition at line 2335 of file pl_comp.c.

References datums_alloc, plpgsql_nDatums, and repalloc().

Referenced by do_compile(), plpgsql_build_record(), plpgsql_build_variable(), plpgsql_parse_dblword(), and plpgsql_parse_tripword().

2336 {
2338  {
2339  datums_alloc *= 2;
2341  }
2342 
2343  new->dno = plpgsql_nDatums;
2345 }
int plpgsql_nDatums
Definition: pl_comp.c:46
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
static int datums_alloc
Definition: pl_comp.c:45
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:962
void plpgsql_append_source_text ( StringInfo  buf,
int  startlocation,
int  endlocation 
)

Definition at line 520 of file pl_scanner.c.

References appendBinaryStringInfo(), Assert, and scanorig.

522 {
523  Assert(startlocation <= endlocation);
524  appendBinaryStringInfo(buf, scanorig + startlocation,
525  endlocation - startlocation);
526 }
static const char * scanorig
Definition: pl_scanner.c:214
#define Assert(condition)
Definition: c.h:664
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:208
int plpgsql_base_yylex ( void  )
PLpgSQL_type* plpgsql_build_datatype ( Oid  typeOid,
int32  typmod,
Oid  collation 
)

Definition at line 2132 of file pl_comp.c.

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

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

2133 {
2134  HeapTuple typeTup;
2135  PLpgSQL_type *typ;
2136 
2137  typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typeOid));
2138  if (!HeapTupleIsValid(typeTup))
2139  elog(ERROR, "cache lookup failed for type %u", typeOid);
2140 
2141  typ = build_datatype(typeTup, typmod, collation);
2142 
2143  ReleaseSysCache(typeTup);
2144 
2145  return typ;
2146 }
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:159
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
static PLpgSQL_type * build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
Definition: pl_comp.c:2152
#define elog
Definition: elog.h:219
PLpgSQL_rec* plpgsql_build_record ( const char *  refname,
int  lineno,
bool  add2namespace 
)

Definition at line 1949 of file pl_comp.c.

References PLpgSQL_rec::dno, PLpgSQL_rec::dtype, PLpgSQL_rec::freetup, PLpgSQL_rec::freetupdesc, PLpgSQL_rec::lineno, palloc0(), plpgsql_adddatum(), PLPGSQL_DTYPE_REC, plpgsql_ns_additem(), PLPGSQL_NSTYPE_REC, pstrdup(), PLpgSQL_rec::refname, PLpgSQL_rec::tup, and PLpgSQL_rec::tupdesc.

Referenced by do_compile(), and plpgsql_build_variable().

1950 {
1951  PLpgSQL_rec *rec;
1952 
1953  rec = palloc0(sizeof(PLpgSQL_rec));
1954  rec->dtype = PLPGSQL_DTYPE_REC;
1955  rec->refname = pstrdup(refname);
1956  rec->lineno = lineno;
1957  rec->tup = NULL;
1958  rec->tupdesc = NULL;
1959  rec->freetup = false;
1960  rec->freetupdesc = false;
1962  if (add2namespace)
1964 
1965  return rec;
1966 }
PLpgSQL_datum_type dtype
Definition: plpgsql.h:302
TupleDesc tupdesc
Definition: plpgsql.h:308
char * pstrdup(const char *in)
Definition: mcxt.c:1076
bool freetup
Definition: plpgsql.h:309
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:94
char * refname
Definition: plpgsql.h:304
void * palloc0(Size size)
Definition: mcxt.c:877
bool freetupdesc
Definition: plpgsql.h:310
HeapTuple tup
Definition: plpgsql.h:307
void plpgsql_adddatum(PLpgSQL_datum *new)
Definition: pl_comp.c:2335
int lineno
Definition: plpgsql.h:305
PLpgSQL_variable* plpgsql_build_variable ( const char *  refname,
int  lineno,
PLpgSQL_type dtype,
bool  add2namespace 
)

Definition at line 1869 of file pl_comp.c.

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

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

1871 {
1873 
1874  switch (dtype->ttype)
1875  {
1876  case PLPGSQL_TTYPE_SCALAR:
1877  {
1878  /* Ordinary scalar datatype */
1879  PLpgSQL_var *var;
1880 
1881  var = palloc0(sizeof(PLpgSQL_var));
1882  var->dtype = PLPGSQL_DTYPE_VAR;
1883  var->refname = pstrdup(refname);
1884  var->lineno = lineno;
1885  var->datatype = dtype;
1886  /* other fields might be filled by caller */
1887 
1888  /* preset to NULL */
1889  var->value = 0;
1890  var->isnull = true;
1891  var->freeval = false;
1892 
1894  if (add2namespace)
1896  var->dno,
1897  refname);
1898  result = (PLpgSQL_variable *) var;
1899  break;
1900  }
1901  case PLPGSQL_TTYPE_ROW:
1902  {
1903  /* Composite type -- build a row variable */
1904  PLpgSQL_row *row;
1905 
1906  row = build_row_from_class(dtype->typrelid);
1907 
1908  row->dtype = PLPGSQL_DTYPE_ROW;
1909  row->refname = pstrdup(refname);
1910  row->lineno = lineno;
1911 
1913  if (add2namespace)
1915  row->dno,
1916  refname);
1917  result = (PLpgSQL_variable *) row;
1918  break;
1919  }
1920  case PLPGSQL_TTYPE_REC:
1921  {
1922  /* "record" type -- build a record variable */
1923  PLpgSQL_rec *rec;
1924 
1925  rec = plpgsql_build_record(refname, lineno, add2namespace);
1926  result = (PLpgSQL_variable *) rec;
1927  break;
1928  }
1929  case PLPGSQL_TTYPE_PSEUDO:
1930  ereport(ERROR,
1931  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1932  errmsg("variable \"%s\" has pseudo-type %s",
1933  refname, format_type_be(dtype->typoid))));
1934  result = NULL; /* keep compiler quiet */
1935  break;
1936  default:
1937  elog(ERROR, "unrecognized ttype: %d", dtype->ttype);
1938  result = NULL; /* keep compiler quiet */
1939  break;
1940  }
1941 
1942  return result;
1943 }
char * refname
Definition: plpgsql.h:281
char * refname
Definition: plpgsql.h:258
static PLpgSQL_row * build_row_from_class(Oid classOid)
Definition: pl_comp.c:1972
PLpgSQL_datum_type dtype
Definition: plpgsql.h:256
char * pstrdup(const char *in)
Definition: mcxt.c:1076
PLpgSQL_type * datatype
Definition: plpgsql.h:261
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:94
PLpgSQL_type_type ttype
Definition: plpgsql.h:180
PLpgSQL_rec * plpgsql_build_record(const char *refname, int lineno, bool add2namespace)
Definition: pl_comp.c:1949
int errcode(int sqlerrcode)
Definition: elog.c:575
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
return result
Definition: formatting.c:1633
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool freeval
Definition: plpgsql.h:271
Oid typrelid
Definition: plpgsql.h:184
void * palloc0(Size size)
Definition: mcxt.c:877
Datum value
Definition: plpgsql.h:269
int lineno
Definition: plpgsql.h:259
int errmsg(const char *fmt,...)
Definition: elog.c:797
void plpgsql_adddatum(PLpgSQL_datum *new)
Definition: pl_comp.c:2335
#define elog
Definition: elog.h:219
PLpgSQL_datum_type dtype
Definition: plpgsql.h:279
int lineno
Definition: plpgsql.h:282
bool isnull
Definition: plpgsql.h:270
Oid typoid
Definition: plpgsql.h:179
PLpgSQL_function* plpgsql_compile ( FunctionCallInfo  fcinfo,
bool  forValidator 
)

Definition at line 137 of file pl_comp.c.

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

Referenced by plpgsql_call_handler(), and plpgsql_validator().

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

Definition at line 799 of file pl_comp.c.

References add_dummy_return(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), ErrorContextCallback::arg, BOOLOID, 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_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, pstrdup(), and VOIDOID.

Referenced by plpgsql_inline_handler().

800 {
801  char *func_name = "inline_code_block";
802  PLpgSQL_function *function;
803  ErrorContextCallback plerrcontext;
804  PLpgSQL_variable *var;
805  int parse_rc;
806  MemoryContext func_cxt;
807 
808  /*
809  * Setup the scanner input and error info. We assume that this function
810  * cannot be invoked recursively, so there's no need to save and restore
811  * the static variables used here.
812  */
813  plpgsql_scanner_init(proc_source);
814 
815  plpgsql_error_funcname = func_name;
816 
817  /*
818  * Setup error traceback support for ereport()
819  */
821  plerrcontext.arg = proc_source;
822  plerrcontext.previous = error_context_stack;
823  error_context_stack = &plerrcontext;
824 
825  /* Do extra syntax checking if check_function_bodies is on */
827 
828  /* Function struct does not live past current statement */
829  function = (PLpgSQL_function *) palloc0(sizeof(PLpgSQL_function));
830 
831  plpgsql_curr_compile = function;
832 
833  /*
834  * All the rest of the compile-time storage (e.g. parse tree) is kept in
835  * its own memory context, so it can be reclaimed easily.
836  */
838  "PL/pgSQL inline code context",
841 
842  function->fn_signature = pstrdup(func_name);
843  function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
844  function->fn_input_collation = InvalidOid;
845  function->fn_cxt = func_cxt;
846  function->out_param_varno = -1; /* set up for no OUT param */
847  function->resolve_option = plpgsql_variable_conflict;
848  function->print_strict_params = plpgsql_print_strict_params;
849 
850  /*
851  * don't do extra validation for inline code as we don't want to add spam
852  * at runtime
853  */
854  function->extra_warnings = 0;
855  function->extra_errors = 0;
856 
857  plpgsql_ns_init();
859  plpgsql_DumpExecTree = false;
861 
862  /* Set up as though in a function returning VOID */
863  function->fn_rettype = VOIDOID;
864  function->fn_retset = false;
865  function->fn_retistuple = false;
866  /* a bit of hardwired knowledge about type VOID here */
867  function->fn_retbyval = true;
868  function->fn_rettyplen = sizeof(int32);
869 
870  /*
871  * Remember if function is STABLE/IMMUTABLE. XXX would it be better to
872  * set this TRUE inside a read-only transaction? Not clear.
873  */
874  function->fn_readonly = false;
875 
876  /*
877  * Create the magic FOUND variable.
878  */
879  var = plpgsql_build_variable("found", 0,
881  -1,
882  InvalidOid),
883  true);
884  function->found_varno = var->dno;
885 
886  /*
887  * Now parse the function's text
888  */
889  parse_rc = plpgsql_yyparse();
890  if (parse_rc != 0)
891  elog(ERROR, "plpgsql parser returned %d", parse_rc);
892  function->action = plpgsql_parse_result;
893 
895 
896  /*
897  * If it returns VOID (always true at the moment), we allow control to
898  * fall off the end without an explicit RETURN statement.
899  */
900  if (function->fn_rettype == VOIDOID)
901  add_dummy_return(function);
902 
903  /*
904  * Complete the function's info
905  */
906  function->fn_nargs = 0;
907 
908  plpgsql_finish_datums(function);
909 
910  /*
911  * Pop the error context stack
912  */
913  error_context_stack = plerrcontext.previous;
914  plpgsql_error_funcname = NULL;
915 
916  plpgsql_check_syntax = false;
917 
920  return function;
921 }
int plpgsql_yyparse(void)
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2132
char * pstrdup(const char *in)
Definition: mcxt.c:1076
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool check_function_bodies
Definition: guc.c:447
struct ErrorContextCallback * previous
Definition: elog.h:238
static void plpgsql_start_datums(void)
Definition: pl_comp.c:2318
signed int int32
Definition: c.h:246
ErrorContextCallback * error_context_stack
Definition: elog.c:88
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:729
#define VOIDOID
Definition: pg_type.h:690
bool plpgsql_check_syntax
Definition: pl_comp.c:52
#define ERROR
Definition: elog.h:43
char * plpgsql_error_funcname
Definition: pl_comp.c:50
bool plpgsql_DumpExecTree
Definition: pl_comp.c:51
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
static void add_dummy_return(PLpgSQL_function *function)
Definition: pl_comp.c:982
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
void plpgsql_ns_init(void)
Definition: pl_funcs.c:45
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void * palloc0(Size size)
Definition: mcxt.c:877
#define InvalidOid
Definition: postgres_ext.h:36
bool plpgsql_print_strict_params
Definition: pl_handler.c:48
static void plpgsql_compile_error_callback(void *arg)
Definition: pl_comp.c:930
int plpgsql_variable_conflict
Definition: pl_handler.c:46
void plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
Definition: pl_funcs.c:56
PLpgSQL_stmt_block * plpgsql_parse_result
Definition: pl_comp.c:43
PLpgSQL_variable * plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
Definition: pl_comp.c:1869
#define BOOLOID
Definition: pg_type.h:288
on_exit_nicely_callback function
void plpgsql_scanner_init(const char *str)
Definition: pl_scanner.c:702
void(* callback)(void *arg)
Definition: elog.h:239
static void plpgsql_finish_datums(PLpgSQL_function *function)
Definition: pl_comp.c:2355
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:57
#define elog
Definition: elog.h:219
PLpgSQL_function * plpgsql_curr_compile
Definition: pl_comp.c:54
void plpgsql_dumptree ( PLpgSQL_function func)

Definition at line 1543 of file pl_funcs.c.

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, dump_block(), dump_expr(), dump_indent, PLpgSQL_row::fieldnames, PLpgSQL_function::fn_signature, i, PLpgSQL_var::isconst, PLpgSQL_stmt_block::lineno, PLpgSQL_function::ndatums, PLpgSQL_row::nfields, PLpgSQL_var::notnull, PLPGSQL_DTYPE_ARRAYELEM, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLpgSQL_var::refname, PLpgSQL_row::refname, PLpgSQL_type::typname, PLpgSQL_type::typoid, and PLpgSQL_row::varnos.

Referenced by do_compile().

1544 {
1545  int i;
1546  PLpgSQL_datum *d;
1547 
1548  printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1549  func->fn_signature);
1550 
1551  printf("\nFunction's data area:\n");
1552  for (i = 0; i < func->ndatums; i++)
1553  {
1554  d = func->datums[i];
1555 
1556  printf(" entry %d: ", i);
1557  switch (d->dtype)
1558  {
1559  case PLPGSQL_DTYPE_VAR:
1560  {
1561  PLpgSQL_var *var = (PLpgSQL_var *) d;
1562 
1563  printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1564  var->refname, var->datatype->typname,
1565  var->datatype->typoid,
1566  var->datatype->atttypmod);
1567  if (var->isconst)
1568  printf(" CONSTANT\n");
1569  if (var->notnull)
1570  printf(" NOT NULL\n");
1571  if (var->default_val != NULL)
1572  {
1573  printf(" DEFAULT ");
1574  dump_expr(var->default_val);
1575  printf("\n");
1576  }
1577  if (var->cursor_explicit_expr != NULL)
1578  {
1579  if (var->cursor_explicit_argrow >= 0)
1580  printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1581 
1582  printf(" CURSOR IS ");
1584  printf("\n");
1585  }
1586  }
1587  break;
1588  case PLPGSQL_DTYPE_ROW:
1589  {
1590  PLpgSQL_row *row = (PLpgSQL_row *) d;
1591  int i;
1592 
1593  printf("ROW %-16s fields", row->refname);
1594  for (i = 0; i < row->nfields; i++)
1595  {
1596  if (row->fieldnames[i])
1597  printf(" %s=var %d", row->fieldnames[i],
1598  row->varnos[i]);
1599  }
1600  printf("\n");
1601  }
1602  break;
1603  case PLPGSQL_DTYPE_REC:
1604  printf("REC %s\n", ((PLpgSQL_rec *) d)->refname);
1605  break;
1607  printf("RECFIELD %-16s of REC %d\n",
1608  ((PLpgSQL_recfield *) d)->fieldname,
1609  ((PLpgSQL_recfield *) d)->recparentno);
1610  break;
1612  printf("ARRAYELEM of VAR %d subscript ",
1613  ((PLpgSQL_arrayelem *) d)->arrayparentno);
1614  dump_expr(((PLpgSQL_arrayelem *) d)->subscript);
1615  printf("\n");
1616  break;
1617  default:
1618  printf("??? unknown data type %d\n", d->dtype);
1619  }
1620  }
1621  printf("\nFunction's statements:\n");
1622 
1623  dump_indent = 0;
1624  printf("%3d:", func->action->lineno);
1625  dump_block(func->action);
1626  printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1627  fflush(stdout);
1628 }
PLpgSQL_datum ** datums
Definition: plpgsql.h:867
char * refname
Definition: plpgsql.h:281
int notnull
Definition: plpgsql.h:263
int isconst
Definition: plpgsql.h:262
char * refname
Definition: plpgsql.h:258
PLpgSQL_stmt_block * action
Definition: plpgsql.h:871
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:265
PLpgSQL_type * datatype
Definition: plpgsql.h:261
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
int cursor_explicit_argrow
Definition: plpgsql.h:266
char ** fieldnames
Definition: plpgsql.h:293
PLpgSQL_expr * default_val
Definition: plpgsql.h:264
int * varnos
Definition: plpgsql.h:294
int nfields
Definition: plpgsql.h:292
static int dump_indent
Definition: pl_funcs.c:751
char * fn_signature
Definition: plpgsql.h:820
char * typname
Definition: plpgsql.h:178
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:888
int32 atttypmod
Definition: plpgsql.h:187
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1537
int i
Oid typoid
Definition: plpgsql.h:179
void plpgsql_exec_event_trigger ( PLpgSQL_function func,
EventTriggerData trigdata 
)

Definition at line 889 of file pl_exec.c.

References PLpgSQL_function::action, ErrorContextCallback::arg, assign_text_var(), ErrorContextCallback::callback, copy_plpgsql_datum(), PLpgSQL_function::datums, PLpgSQL_execstate::datums, ereport, PLpgSQL_execstate::err_stmt, PLpgSQL_execstate::err_text, errcode(), errmsg(), ERROR, error_context_stack, EventTriggerData::event, exec_eval_cleanup(), exec_stmt_block(), PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, gettext_noop, i, PLpgSQL_execstate::ndatums, plpgsql_destroy_econtext(), plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, ErrorContextCallback::previous, EventTriggerData::tag, PLpgSQL_function::tg_event_varno, and PLpgSQL_function::tg_tag_varno.

Referenced by plpgsql_call_handler().

890 {
891  PLpgSQL_execstate estate;
892  ErrorContextCallback plerrcontext;
893  int i;
894  int rc;
895  PLpgSQL_var *var;
896 
897  /*
898  * Setup the execution state
899  */
900  plpgsql_estate_setup(&estate, func, NULL, NULL);
901 
902  /*
903  * Setup error traceback support for ereport()
904  */
905  plerrcontext.callback = plpgsql_exec_error_callback;
906  plerrcontext.arg = &estate;
907  plerrcontext.previous = error_context_stack;
908  error_context_stack = &plerrcontext;
909 
910  /*
911  * Make local execution copies of all the datums
912  */
913  estate.err_text = gettext_noop("during initialization of execution state");
914  for (i = 0; i < estate.ndatums; i++)
915  estate.datums[i] = copy_plpgsql_datum(func->datums[i]);
916 
917  /*
918  * Assign the special tg_ variables
919  */
920  var = (PLpgSQL_var *) (estate.datums[func->tg_event_varno]);
921  assign_text_var(&estate, var, trigdata->event);
922 
923  var = (PLpgSQL_var *) (estate.datums[func->tg_tag_varno]);
924  assign_text_var(&estate, var, trigdata->tag);
925 
926  /*
927  * Let the instrumentation plugin peek at this function
928  */
929  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
930  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
931 
932  /*
933  * Now call the toplevel block of statements
934  */
935  estate.err_text = NULL;
936  estate.err_stmt = (PLpgSQL_stmt *) (func->action);
937  rc = exec_stmt_block(&estate, func->action);
938  if (rc != PLPGSQL_RC_RETURN)
939  {
940  estate.err_stmt = NULL;
941  estate.err_text = NULL;
942  ereport(ERROR,
943  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
944  errmsg("control reached end of trigger procedure without RETURN")));
945  }
946 
947  estate.err_stmt = NULL;
948  estate.err_text = gettext_noop("during function exit");
949 
950  /*
951  * Let the instrumentation plugin peek at this function
952  */
953  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
954  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
955 
956  /* Clean up any leftover temporary memory */
957  plpgsql_destroy_econtext(&estate);
958  exec_eval_cleanup(&estate);
959  /* stmt_mcontext will be destroyed when function's main context is */
960 
961  /*
962  * Pop the error context stack
963  */
964  error_context_stack = plerrcontext.previous;
965 
966  return;
967 }
int tg_event_varno
Definition: plpgsql.h:854
PLpgSQL_datum ** datums
Definition: plpgsql.h:867
PLpgSQL_stmt * err_stmt
Definition: plpgsql.h:932
PLpgSQL_stmt_block * action
Definition: plpgsql.h:871
static void plpgsql_exec_error_callback(void *arg)
Definition: pl_exec.c:973
#define gettext_noop(x)
Definition: c.h:139
static void plpgsql_estate_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func, ReturnSetInfo *rsi, EState *simple_eval_estate)
Definition: pl_exec.c:3395
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * tag
Definition: event_trigger.h:28
static void exec_eval_cleanup(PLpgSQL_execstate *estate)
Definition: pl_exec.c:3538
struct ErrorContextCallback * previous
Definition: elog.h:238
PLpgSQL_datum ** datums
Definition: plpgsql.h:908
ErrorContextCallback * error_context_stack
Definition: elog.c:88
#define ERROR
Definition: elog.h:43
const char * event
Definition: event_trigger.h:26
static void plpgsql_destroy_econtext(PLpgSQL_execstate *estate)
Definition: pl_exec.c:6822
#define ereport(elevel, rest)
Definition: elog.h:122
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:58
const char * err_text
Definition: plpgsql.h:933
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:972
static void assign_text_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, const char *str)
Definition: pl_exec.c:6937
static int exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
Definition: pl_exec.c:1177
void(* callback)(void *arg)
Definition: elog.h:239
int errmsg(const char *fmt,...)
Definition: elog.c:797
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:973
int i
static PLpgSQL_datum * copy_plpgsql_datum(PLpgSQL_datum *datum)
Definition: pl_exec.c:1031
Datum plpgsql_exec_function ( PLpgSQL_function func,
FunctionCallInfo  fcinfo,
EState simple_eval_estate 
)

Definition at line 329 of file pl_exec.c.

References PLpgSQL_function::action, ReturnSetInfo::allowedModes, FunctionCallInfoData::arg, ErrorContextCallback::arg, FunctionCallInfoData::argnull, assign_simple_var(), ErrorContextCallback::callback, convert_tuples_by_position(), copy_plpgsql_datum(), CreateTupleDescCopy(), CurrentMemoryContext, PLpgSQL_var::datatype, DatumGetPointer, PLpgSQL_function::datums, PLpgSQL_execstate::datums, do_convert_tuple(), PLpgSQL_datum::dtype, elog, ereport, PLpgSQL_execstate::err_stmt, 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_stmt_block(), expand_array(), PLpgSQL_function::fn_argvarnos, PLpgSQL_function::fn_nargs, PLpgSQL_function::fn_retbyval, PLpgSQL_function::fn_rettype, PLpgSQL_function::fn_rettyplen, PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, get_call_result_type(), gettext_noop, i, IsA, FunctionCallInfoData::isnull, PLpgSQL_var::isnull, MemoryContextSwitchTo(), PLpgSQL_execstate::ndatums, plpgsql_destroy_econtext(), PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, PointerGetDatum, ErrorContextCallback::previous, FunctionCallInfoData::resultinfo, PLpgSQL_execstate::retisnull, PLpgSQL_execstate::retisset, PLpgSQL_execstate::retistuple, PLpgSQL_execstate::rettupdesc, PLpgSQL_execstate::rettype, ReturnSetInfo::returnMode, PLpgSQL_execstate::retval, PLpgSQL_execstate::rsi, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, SPI_datumTransfer(), SPI_returntuple(), TransferExpandedObject(), PLpgSQL_execstate::tuple_store, PLpgSQL_execstate::tuple_store_cxt, TYPEFUNC_COMPOSITE, TYPEFUNC_RECORD, PLpgSQL_type::typisarray, PLpgSQL_var::value, VARATT_IS_EXTERNAL_EXPANDED_RO, and VARATT_IS_EXTERNAL_EXPANDED_RW.

Referenced by plpgsql_call_handler(), and plpgsql_inline_handler().

331 {
332  PLpgSQL_execstate estate;
333  ErrorContextCallback plerrcontext;
334  int i;
335  int rc;
336 
337  /*
338  * Setup the execution state
339  */
340  plpgsql_estate_setup(&estate, func, (ReturnSetInfo *) fcinfo->resultinfo,
341  simple_eval_estate);
342 
343  /*
344  * Setup error traceback support for ereport()
345  */
346  plerrcontext.callback = plpgsql_exec_error_callback;
347  plerrcontext.arg = &estate;
348  plerrcontext.previous = error_context_stack;
349  error_context_stack = &plerrcontext;
350 
351  /*
352  * Make local execution copies of all the datums
353  */
354  estate.err_text = gettext_noop("during initialization of execution state");
355  for (i = 0; i < estate.ndatums; i++)
356  estate.datums[i] = copy_plpgsql_datum(func->datums[i]);
357 
358  /*
359  * Store the actual call argument values into the appropriate variables
360  */
361  estate.err_text = gettext_noop("while storing call arguments into local variables");
362  for (i = 0; i < func->fn_nargs; i++)
363  {
364  int n = func->fn_argvarnos[i];
365 
366  switch (estate.datums[n]->dtype)
367  {
368  case PLPGSQL_DTYPE_VAR:
369  {
370  PLpgSQL_var *var = (PLpgSQL_var *) estate.datums[n];
371 
372  assign_simple_var(&estate, var,
373  fcinfo->arg[i],
374  fcinfo->argnull[i],
375  false);
376 
377  /*
378  * Force any array-valued parameter to be stored in
379  * expanded form in our local variable, in hopes of
380  * improving efficiency of uses of the variable. (This is
381  * a hack, really: why only arrays? Need more thought
382  * about which cases are likely to win. See also
383  * typisarray-specific heuristic in exec_assign_value.)
384  *
385  * Special cases: If passed a R/W expanded pointer, assume
386  * we can commandeer the object rather than having to copy
387  * it. If passed a R/O expanded pointer, just keep it as
388  * the value of the variable for the moment. (We'll force
389  * it to R/W if the variable gets modified, but that may
390  * very well never happen.)
391  */
392  if (!var->isnull && var->datatype->typisarray)
393  {
395  {
396  /* take ownership of R/W object */
397  assign_simple_var(&estate, var,
400  false,
401  true);
402  }
404  {
405  /* R/O pointer, keep it as-is until assigned to */
406  }
407  else
408  {
409  /* flat array, so force to expanded form */
410  assign_simple_var(&estate, var,
411  expand_array(var->value,
413  NULL),
414  false,
415  true);
416  }
417  }
418  }
419  break;
420 
421  case PLPGSQL_DTYPE_ROW:
422  {
423  PLpgSQL_row *row = (PLpgSQL_row *) estate.datums[n];
424 
425  if (!fcinfo->argnull[i])
426  {
427  /* Assign row value from composite datum */
428  exec_move_row_from_datum(&estate, NULL, row,
429  fcinfo->arg[i]);
430  }
431  else
432  {
433  /* If arg is null, treat it as an empty row */
434  exec_move_row(&estate, NULL, row, NULL, NULL);
435  }
436  /* clean up after exec_move_row() */
437  exec_eval_cleanup(&estate);
438  }
439  break;
440 
441  default:
442  elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
443  }
444  }
445 
446  estate.err_text = gettext_noop("during function entry");
447 
448  /*
449  * Set the magic variable FOUND to false
450  */
451  exec_set_found(&estate, false);
452 
453  /*
454  * Let the instrumentation plugin peek at this function
455  */
456  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
457  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
458 
459  /*
460  * Now call the toplevel block of statements
461  */
462  estate.err_text = NULL;
463  estate.err_stmt = (PLpgSQL_stmt *) (func->action);
464  rc = exec_stmt_block(&estate, func->action);
465  if (rc != PLPGSQL_RC_RETURN)
466  {
467  estate.err_stmt = NULL;
468  estate.err_text = NULL;
469  ereport(ERROR,
470  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
471  errmsg("control reached end of function without RETURN")));
472  }
473 
474  /*
475  * We got a return value - process it
476  */
477  estate.err_stmt = NULL;
478  estate.err_text = gettext_noop("while casting return value to function's return type");
479 
480  fcinfo->isnull = estate.retisnull;
481 
482  if (estate.retisset)
483  {
484  ReturnSetInfo *rsi = estate.rsi;
485 
486  /* Check caller can handle a set result */
487  if (!rsi || !IsA(rsi, ReturnSetInfo) ||
488  (rsi->allowedModes & SFRM_Materialize) == 0)
489  ereport(ERROR,
490  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
491  errmsg("set-valued function called in context that cannot accept a set")));
493 
494  /* If we produced any tuples, send back the result */
495  if (estate.tuple_store)
496  {
497  rsi->setResult = estate.tuple_store;
498  if (estate.rettupdesc)
499  {
500  MemoryContext oldcxt;
501 
502  oldcxt = MemoryContextSwitchTo(estate.tuple_store_cxt);
503  rsi->setDesc = CreateTupleDescCopy(estate.rettupdesc);
504  MemoryContextSwitchTo(oldcxt);
505  }
506  }
507  estate.retval = (Datum) 0;
508  fcinfo->isnull = true;
509  }
510  else if (!estate.retisnull)
511  {
512  if (estate.retistuple)
513  {
514  /*
515  * We have to check that the returned tuple actually matches the
516  * expected result type. XXX would be better to cache the tupdesc
517  * instead of repeating get_call_result_type()
518  */
519  HeapTuple rettup = (HeapTuple) DatumGetPointer(estate.retval);
520  TupleDesc tupdesc;
521  TupleConversionMap *tupmap;
522 
523  switch (get_call_result_type(fcinfo, NULL, &tupdesc))
524  {
525  case TYPEFUNC_COMPOSITE:
526  /* got the expected result rowtype, now check it */
527  tupmap = convert_tuples_by_position(estate.rettupdesc,
528  tupdesc,
529  gettext_noop("returned record type does not match expected record type"));
530  /* it might need conversion */
531  if (tupmap)
532  rettup = do_convert_tuple(rettup, tupmap);
533  /* no need to free map, we're about to return anyway */
534  break;
535  case TYPEFUNC_RECORD:
536 
537  /*
538  * Failed to determine actual type of RECORD. We could
539  * raise an error here, but what this means in practice is
540  * that the caller is expecting any old generic rowtype,
541  * so we don't really need to be restrictive. Pass back
542  * the generated result type, instead.
543  */
544  tupdesc = estate.rettupdesc;
545  if (tupdesc == NULL) /* shouldn't happen */
546  elog(ERROR, "return type must be a row type");
547  break;
548  default:
549  /* shouldn't get here if retistuple is true ... */
550  elog(ERROR, "return type must be a row type");
551  break;
552  }
553 
554  /*
555  * Copy tuple to upper executor memory, as a tuple Datum. Make
556  * sure it is labeled with the caller-supplied tuple type.
557  */
558  estate.retval = PointerGetDatum(SPI_returntuple(rettup, tupdesc));
559  }
560  else
561  {
562  /* Cast value to proper type */
563  estate.retval = exec_cast_value(&estate,
564  estate.retval,
565  &fcinfo->isnull,
566  estate.rettype,
567  -1,
568  func->fn_rettype,
569  -1);
570 
571  /*
572  * If the function's return type isn't by value, copy the value
573  * into upper executor memory context. However, if we have a R/W
574  * expanded datum, we can just transfer its ownership out to the
575  * upper executor context.
576  */
577  if (!fcinfo->isnull && !func->fn_retbyval)
578  estate.retval = SPI_datumTransfer(estate.retval,
579  false,
580  func->fn_rettyplen);
581  }
582  }
583 
584  estate.err_text = gettext_noop("during function exit");
585 
586  /*
587  * Let the instrumentation plugin peek at this function
588  */
589  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
590  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
591 
592  /* Clean up any leftover temporary memory */
593  plpgsql_destroy_econtext(&estate);
594  exec_eval_cleanup(&estate);
595  /* stmt_mcontext will be destroyed when function's main context is */
596 
597  /*
598  * Pop the error context stack
599  */
600  error_context_stack = plerrcontext.previous;
601 
602  /*
603  * Return the function's result
604  */
605  return estate.retval;
606 }
bool fn_retbyval
Definition: plpgsql.h:831
PLpgSQL_datum ** datums
Definition: plpgsql.h:867
int fn_argvarnos[FUNC_MAX_ARGS]
Definition: plpgsql.h:837
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:102
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
HeapTupleData * HeapTuple
Definition: htup.h:70
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc)
Definition: spi.c:658
static void exec_move_row_from_datum(PLpgSQL_execstate *estate, PLpgSQL_rec *rec, PLpgSQL_row *row, Datum value)
Definition: pl_exec.c:6191
PLpgSQL_stmt * err_stmt
Definition: plpgsql.h:932
TupleConversionMap * convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg)
Definition: tupconvert.c:66
PLpgSQL_stmt_block * action
Definition: plpgsql.h:871
#define PointerGetDatum(X)
Definition: postgres.h:562
PLpgSQL_type * datatype
Definition: plpgsql.h:261
Datum expand_array(Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
static void plpgsql_exec_error_callback(void *arg)
Definition: pl_exec.c:973
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define gettext_noop(x)
Definition: c.h:139
static void plpgsql_estate_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func, ReturnSetInfo *rsi, EState *simple_eval_estate)
Definition: pl_exec.c:3395
int errcode(int sqlerrcode)
Definition: elog.c:575
static void assign_simple_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, Datum newvalue, bool isnull, bool freeable)
Definition: pl_exec.c:6902
static void exec_eval_cleanup(PLpgSQL_execstate *estate)
Definition: pl_exec.c:3538
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
struct ErrorContextCallback * previous
Definition: elog.h:238
PLpgSQL_datum ** datums
Definition: plpgsql.h:908
ErrorContextCallback * error_context_stack
Definition: elog.c:88
Datum TransferExpandedObject(Datum d, MemoryContext new_parent)
static Datum exec_cast_value(PLpgSQL_execstate *estate, Datum value, bool *isnull, Oid valtype, int32 valtypmod, Oid reqtype, int32 reqtypmod)
Definition: pl_exec.c:6265
TupleDesc rettupdesc
Definition: plpgsql.h:895
#define ERROR
Definition: elog.h:43
MemoryContext tuple_store_cxt
Definition: plpgsql.h:901
Datum SPI_datumTransfer(Datum value, bool typByVal, int typLen)
Definition: spi.c:947
static void plpgsql_destroy_econtext(PLpgSQL_execstate *estate)
Definition: pl_exec.c:6822
fmNodePtr resultinfo
Definition: fmgr.h:81
ReturnSetInfo * rsi
Definition: plpgsql.h:903
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
static void exec_move_row(PLpgSQL_execstate *estate, PLpgSQL_rec *rec, PLpgSQL_row *row, HeapTuple tup, TupleDesc tupdesc)
Definition: pl_exec.c:5945
#define ereport(elevel, rest)
Definition: elog.h:122
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:58
Tuplestorestate * tuple_store
Definition: plpgsql.h:900
bool typisarray
Definition: plpgsql.h:186
uintptr_t Datum
Definition: postgres.h:372
const char * err_text
Definition: plpgsql.h:933
Datum value
Definition: plpgsql.h:269
int allowedModes
Definition: execnodes.h:268
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
SetFunctionReturnMode returnMode
Definition: execnodes.h:270
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:972
#define VARATT_IS_EXTERNAL_EXPANDED_RO(PTR)
Definition: postgres.h:319
static void exec_set_found(PLpgSQL_execstate *estate, bool state)
Definition: pl_exec.c:6756
HeapTuple do_convert_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:354
Tuplestorestate * setResult
Definition: execnodes.h:273
#define DatumGetPointer(X)
Definition: postgres.h:555
static int exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
Definition: pl_exec.c:1177
TupleDesc setDesc
Definition: execnodes.h:274
void(* callback)(void *arg)
Definition: elog.h:239
int errmsg(const char *fmt,...)
Definition: elog.c:797
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:973
int i
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:321
static PLpgSQL_datum * copy_plpgsql_datum(PLpgSQL_datum *datum)
Definition: pl_exec.c:1031
#define elog
Definition: elog.h:219
bool isnull
Definition: plpgsql.h:270
Oid plpgsql_exec_get_datum_type ( PLpgSQL_execstate estate,
PLpgSQL_datum datum 
)

Definition at line 4944 of file pl_exec.c.

References BlessTupleDesc(), PLpgSQL_var::datatype, PLpgSQL_execstate::datums, PLpgSQL_datum::dtype, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, PLpgSQL_recfield::fieldname, InvalidOid, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLpgSQL_recfield::recparentno, PLpgSQL_rec::refname, PLpgSQL_row::rowtupdesc, SPI_ERROR_NOATTRIBUTE, SPI_fnumber(), SPI_gettypeid(), tupleDesc::tdtypeid, PLpgSQL_rec::tupdesc, and PLpgSQL_type::typoid.

Referenced by exec_stmt_foreach_a().

4946 {
4947  Oid typeid;
4948 
4949  switch (datum->dtype)
4950  {
4951  case PLPGSQL_DTYPE_VAR:
4952  {
4953  PLpgSQL_var *var = (PLpgSQL_var *) datum;
4954 
4955  typeid = var->datatype->typoid;
4956  break;
4957  }
4958 
4959  case PLPGSQL_DTYPE_ROW:
4960  {
4961  PLpgSQL_row *row = (PLpgSQL_row *) datum;
4962 
4963  if (!row->rowtupdesc) /* should not happen */
4964  elog(ERROR, "row variable has no tupdesc");
4965  /* Make sure we have a valid type/typmod setting */
4966  BlessTupleDesc(row->rowtupdesc);
4967  typeid = row->rowtupdesc->tdtypeid;
4968  break;
4969  }
4970 
4971  case PLPGSQL_DTYPE_REC:
4972  {
4973  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
4974 
4975  if (rec->tupdesc == NULL)
4976  ereport(ERROR,
4977  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4978  errmsg("record \"%s\" is not assigned yet",
4979  rec->refname),
4980  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
4981  /* Make sure we have a valid type/typmod setting */
4982  BlessTupleDesc(rec->tupdesc);
4983  typeid = rec->tupdesc->tdtypeid;
4984  break;
4985  }
4986 
4988  {
4989  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
4990  PLpgSQL_rec *rec;
4991  int fno;
4992 
4993  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
4994  if (rec->tupdesc == NULL)
4995  ereport(ERROR,
4996  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4997  errmsg("record \"%s\" is not assigned yet",
4998  rec->refname),
4999  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
5000  fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
5001  if (fno == SPI_ERROR_NOATTRIBUTE)
5002  ereport(ERROR,
5003  (errcode(ERRCODE_UNDEFINED_COLUMN),
5004  errmsg("record \"%s\" has no field \"%s\"",
5005  rec->refname, recfield->fieldname)));
5006  typeid = SPI_gettypeid(rec->tupdesc, fno);
5007  break;
5008  }
5009 
5010  default:
5011  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5012  typeid = InvalidOid; /* keep compiler quiet */
5013  break;
5014  }
5015 
5016  return typeid;
5017 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:761
TupleDesc tupdesc
Definition: plpgsql.h:308
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:894
Oid tdtypeid
Definition: tupdesc.h:74
PLpgSQL_type * datatype
Definition: plpgsql.h:261
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
char * refname
Definition: plpgsql.h:304
PLpgSQL_datum ** datums
Definition: plpgsql.h:908
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
#define SPI_ERROR_NOATTRIBUTE
Definition: spi.h:44
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:797
TupleDesc rowtupdesc
Definition: plpgsql.h:285
#define elog
Definition: elog.h:219
char * fieldname
Definition: plpgsql.h:320
Oid typoid
Definition: plpgsql.h:179
void plpgsql_exec_get_datum_type_info ( PLpgSQL_execstate estate,
PLpgSQL_datum datum,
Oid typeid,
int32 typmod,
Oid collation 
)

Definition at line 5026 of file pl_exec.c.

References PLpgSQL_type::atttypmod, BlessTupleDesc(), PLpgSQL_type::collation, PLpgSQL_var::datatype, PLpgSQL_execstate::datums, PLpgSQL_datum::dtype, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, PLpgSQL_recfield::fieldname, InvalidOid, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLpgSQL_recfield::recparentno, PLpgSQL_rec::refname, PLpgSQL_row::rowtupdesc, SPI_ERROR_NOATTRIBUTE, SPI_fnumber(), SPI_gettypeid(), tupleDesc::tdtypeid, PLpgSQL_rec::tupdesc, TupleDescAttr, and PLpgSQL_type::typoid.

Referenced by make_datum_param().

5029 {
5030  switch (datum->dtype)
5031  {
5032  case PLPGSQL_DTYPE_VAR:
5033  {
5034  PLpgSQL_var *var = (PLpgSQL_var *) datum;
5035 
5036  *typeid = var->datatype->typoid;
5037  *typmod = var->datatype->atttypmod;
5038  *collation = var->datatype->collation;
5039  break;
5040  }
5041 
5042  case PLPGSQL_DTYPE_ROW:
5043  {
5044  PLpgSQL_row *row = (PLpgSQL_row *) datum;
5045 
5046  if (!row->rowtupdesc) /* should not happen */
5047  elog(ERROR, "row variable has no tupdesc");
5048  /* Make sure we have a valid type/typmod setting */
5049  BlessTupleDesc(row->rowtupdesc);
5050  *typeid = row->rowtupdesc->tdtypeid;
5051  /* do NOT return the mutable typmod of a RECORD variable */
5052  *typmod = -1;
5053  /* composite types are never collatable */
5054  *collation = InvalidOid;
5055  break;
5056  }
5057 
5058  case PLPGSQL_DTYPE_REC:
5059  {
5060  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
5061 
5062  if (rec->tupdesc == NULL)
5063  ereport(ERROR,
5064  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
5065  errmsg("record \"%s\" is not assigned yet",
5066  rec->refname),
5067  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
5068  /* Make sure we have a valid type/typmod setting */
5069  BlessTupleDesc(rec->tupdesc);
5070  *typeid = rec->tupdesc->tdtypeid;
5071  /* do NOT return the mutable typmod of a RECORD variable */
5072  *typmod = -1;
5073  /* composite types are never collatable */
5074  *collation = InvalidOid;
5075  break;
5076  }
5077 
5079  {
5080  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
5081  PLpgSQL_rec *rec;
5082  int fno;
5083 
5084  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
5085  if (rec->tupdesc == NULL)
5086  ereport(ERROR,
5087  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
5088  errmsg("record \"%s\" is not assigned yet",
5089  rec->refname),
5090  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
5091  fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
5092  if (fno == SPI_ERROR_NOATTRIBUTE)
5093  ereport(ERROR,
5094  (errcode(ERRCODE_UNDEFINED_COLUMN),
5095  errmsg("record \"%s\" has no field \"%s\"",
5096  rec->refname, recfield->fieldname)));
5097  *typeid = SPI_gettypeid(rec->tupdesc, fno);
5098  if (fno > 0)
5099  {
5100  Form_pg_attribute attr = TupleDescAttr(rec->tupdesc, fno - 1);
5101 
5102  *typmod = attr->atttypmod;
5103  }
5104  else
5105  *typmod = -1;
5106  if (fno > 0)
5107  {
5108  Form_pg_attribute attr = TupleDescAttr(rec->tupdesc, fno - 1);
5109 
5110  *collation = attr->attcollation;
5111  }
5112  else /* no system column types have collation */
5113  *collation = InvalidOid;
5114  break;
5115  }
5116 
5117  default:
5118  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5119  *typeid = InvalidOid; /* keep compiler quiet */
5120  *typmod = -1;
5121  *collation = InvalidOid;
5122  break;
5123  }
5124 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:761
TupleDesc tupdesc
Definition: plpgsql.h:308
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:894
Oid tdtypeid
Definition: tupdesc.h:74
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
PLpgSQL_type * datatype
Definition: plpgsql.h:261
int errcode(int sqlerrcode)
Definition: elog.c:575
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
char * refname
Definition: plpgsql.h:304
PLpgSQL_datum ** datums
Definition: plpgsql.h:908
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
#define SPI_ERROR_NOATTRIBUTE
Definition: spi.h:44
int errdetail(const char *fmt,...)
Definition: elog.c:873
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define ereport(elevel, rest)
Definition: elog.h:122
Oid collation
Definition: plpgsql.h:185
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:797
int32 atttypmod
Definition: plpgsql.h:187
TupleDesc rowtupdesc
Definition: plpgsql.h:285
#define elog
Definition: elog.h:219
char * fieldname
Definition: plpgsql.h:320
Oid typoid
Definition: plpgsql.h:179
HeapTuple plpgsql_exec_trigger ( PLpgSQL_function func,
TriggerData trigdata 
)

Definition at line 615 of file pl_exec.c.

References PLpgSQL_function::action, ErrorContextCallback::arg, Assert, assign_simple_var(), assign_text_var(), ErrorContextCallback::callback, construct_md_array(), convert_tuples_by_position(), copy_plpgsql_datum(), CStringGetDatum, CStringGetTextDatum, DatumGetPointer, PLpgSQL_function::datums, PLpgSQL_execstate::datums, DirectFunctionCall1, do_convert_tuple(), elog, ereport, PLpgSQL_execstate::err_stmt, PLpgSQL_execstate::err_text, errcode(), errmsg(), ERROR, error_context_stack, exec_eval_cleanup(), exec_set_found(), exec_stmt_block(), PLpgSQL_rec::freetup, PLpgSQL_rec::freetupdesc, PLpgSQL_plugin::func_beg, PLpgSQL_plugin::func_end, get_namespace_name(), gettext_noop, i, Int16GetDatum, namein(), PLpgSQL_execstate::ndatums, PLpgSQL_function::new_varno, ObjectIdGetDatum, PLpgSQL_function::old_varno, palloc(), plpgsql_destroy_econtext(), plpgsql_estate_setup(), plpgsql_exec_error_callback(), plpgsql_plugin_ptr, PLPGSQL_RC_RETURN, PointerGetDatum, ErrorContextCallback::previous, RelationData::rd_att, RelationData::rd_id, RelationGetNamespace, RelationGetRelationName, PLpgSQL_execstate::retisnull, PLpgSQL_execstate::retisset, PLpgSQL_execstate::rettupdesc, PLpgSQL_execstate::retval, SPI_copytuple(), SPI_register_trigger_data(), TEXTOID, PLpgSQL_function::tg_argv_varno, TriggerData::tg_event, PLpgSQL_function::tg_level_varno, PLpgSQL_function::tg_name_varno, PLpgSQL_function::tg_nargs_varno, TriggerData::tg_newtuple, PLpgSQL_function::tg_op_varno, TriggerData::tg_relation, PLpgSQL_function::tg_relid_varno, PLpgSQL_function::tg_relname_varno, PLpgSQL_function::tg_table_name_varno, PLpgSQL_function::tg_table_schema_varno, TriggerData::tg_trigger, TriggerData::tg_trigtuple, PLpgSQL_function::tg_when_varno, Trigger::tgargs, Trigger::tgname, Trigger::tgnargs, TRIGGER_FIRED_AFTER, TRIGGER_FIRED_BEFORE, TRIGGER_FIRED_BY_DELETE, TRIGGER_FIRED_BY_INSERT, TRIGGER_FIRED_BY_TRUNCATE, TRIGGER_FIRED_BY_UPDATE, TRIGGER_FIRED_FOR_ROW, TRIGGER_FIRED_FOR_STATEMENT, TRIGGER_FIRED_INSTEAD, PLpgSQL_rec::tup, and PLpgSQL_rec::tupdesc.

Referenced by plpgsql_call_handler().

617 {
618  PLpgSQL_execstate estate;
619  ErrorContextCallback plerrcontext;
620  int i;
621  int rc;
622  PLpgSQL_var *var;
623  PLpgSQL_rec *rec_new,
624  *rec_old;
625  HeapTuple rettup;
626 
627  /*
628  * Setup the execution state
629  */
630  plpgsql_estate_setup(&estate, func, NULL, NULL);
631 
632  /*
633  * Setup error traceback support for ereport()
634  */
635  plerrcontext.callback = plpgsql_exec_error_callback;
636  plerrcontext.arg = &estate;
637  plerrcontext.previous = error_context_stack;
638  error_context_stack = &plerrcontext;
639 
640  /*
641  * Make local execution copies of all the datums
642  */
643  estate.err_text = gettext_noop("during initialization of execution state");
644  for (i = 0; i < estate.ndatums; i++)
645  estate.datums[i] = copy_plpgsql_datum(func->datums[i]);
646 
647  /*
648  * Put the OLD and NEW tuples into record variables
649  *
650  * We make the tupdescs available in both records even though only one may
651  * have a value. This allows parsing of record references to succeed in
652  * functions that are used for multiple trigger types. For example, we
653  * might have a test like "if (TG_OP = 'INSERT' and NEW.foo = 'xyz')",
654  * which should parse regardless of the current trigger type.
655  */
656  rec_new = (PLpgSQL_rec *) (estate.datums[func->new_varno]);
657  rec_new->freetup = false;
658  rec_new->tupdesc = trigdata->tg_relation->rd_att;
659  rec_new->freetupdesc = false;
660  rec_old = (PLpgSQL_rec *) (estate.datums[func->old_varno]);
661  rec_old->freetup = false;
662  rec_old->tupdesc = trigdata->tg_relation->rd_att;
663  rec_old->freetupdesc = false;
664 
665  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
666  {
667  /*
668  * Per-statement triggers don't use OLD/NEW variables
669  */
670  rec_new->tup = NULL;
671  rec_old->tup = NULL;
672  }
673  else if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
674  {
675  rec_new->tup = trigdata->tg_trigtuple;
676  rec_old->tup = NULL;
677  }
678  else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
679  {
680  rec_new->tup = trigdata->tg_newtuple;
681  rec_old->tup = trigdata->tg_trigtuple;
682  }
683  else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
684  {
685  rec_new->tup = NULL;
686  rec_old->tup = trigdata->tg_trigtuple;
687  }
688  else
689  elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE");
690 
691  /* Make transition tables visible to this SPI connection */
692  rc = SPI_register_trigger_data(trigdata);
693  Assert(rc >= 0);
694 
695  /*
696  * Assign the special tg_ variables
697  */
698 
699  var = (PLpgSQL_var *) (estate.datums[func->tg_op_varno]);
700  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
701  assign_text_var(&estate, var, "INSERT");
702  else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
703  assign_text_var(&estate, var, "UPDATE");
704  else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
705  assign_text_var(&estate, var, "DELETE");
706  else if (TRIGGER_FIRED_BY_TRUNCATE(trigdata->tg_event))
707  assign_text_var(&estate, var, "TRUNCATE");
708  else
709  elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, UPDATE, or TRUNCATE");
710 
711  var = (PLpgSQL_var *) (estate.datums[func->tg_name_varno]);
712  assign_simple_var(&estate, var,
714  CStringGetDatum(trigdata->tg_trigger->tgname)),
715  false, true);
716 
717  var = (PLpgSQL_var *) (estate.datums[func->tg_when_varno]);
718  if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
719  assign_text_var(&estate, var, "BEFORE");
720  else if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
721  assign_text_var(&estate, var, "AFTER");
722  else if (TRIGGER_FIRED_INSTEAD(trigdata->tg_event))
723  assign_text_var(&estate, var, "INSTEAD OF");
724  else
725  elog(ERROR, "unrecognized trigger execution time: not BEFORE, AFTER, or INSTEAD OF");
726 
727  var = (PLpgSQL_var *) (estate.datums[func->tg_level_varno]);
728  if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
729  assign_text_var(&estate, var, "ROW");
730  else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
731  assign_text_var(&estate, var, "STATEMENT");
732  else
733  elog(ERROR, "unrecognized trigger event type: not ROW or STATEMENT");
734 
735  var = (PLpgSQL_var *) (estate.datums[func->tg_relid_varno]);
736  assign_simple_var(&estate, var,
737  ObjectIdGetDatum(trigdata->tg_relation->rd_id),
738  false, false);
739 
740  var = (PLpgSQL_var *) (estate.datums[func->tg_relname_varno]);
741  assign_simple_var(&estate, var,
744  false, true);
745 
746  var = (PLpgSQL_var *) (estate.datums[func->tg_table_name_varno]);
747  assign_simple_var(&estate, var,
750  false, true);
751 
752  var = (PLpgSQL_var *) (estate.datums[func->tg_table_schema_varno]);
753  assign_simple_var(&estate, var,
757  trigdata->tg_relation)))),
758  false, true);
759 
760  var = (PLpgSQL_var *) (estate.datums[func->tg_nargs_varno]);
761  assign_simple_var(&estate, var,
762  Int16GetDatum(trigdata->tg_trigger->tgnargs),
763  false, false);
764 
765  var = (PLpgSQL_var *) (estate.datums[func->tg_argv_varno]);
766  if (trigdata->tg_trigger->tgnargs > 0)
767  {
768  /*
769  * For historical reasons, tg_argv[] subscripts start at zero not one.
770  * So we can't use construct_array().
771  */
772  int nelems = trigdata->tg_trigger->tgnargs;
773  Datum *elems;
774  int dims[1];
775  int lbs[1];
776 
777  elems = palloc(sizeof(Datum) * nelems);
778  for (i = 0; i < nelems; i++)
779  elems[i] = CStringGetTextDatum(trigdata->tg_trigger->tgargs[i]);
780  dims[0] = nelems;
781  lbs[0] = 0;
782 
783  assign_simple_var(&estate, var,
785  1, dims, lbs,
786  TEXTOID,
787  -1, false, 'i')),
788  false, true);
789  }
790  else
791  {
792  assign_simple_var(&estate, var, (Datum) 0, true, false);
793  }
794 
795  estate.err_text = gettext_noop("during function entry");
796 
797  /*
798  * Set the magic variable FOUND to false
799  */
800  exec_set_found(&estate, false);
801 
802  /*
803  * Let the instrumentation plugin peek at this function
804  */
805  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_beg)
806  ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
807 
808  /*
809  * Now call the toplevel block of statements
810  */
811  estate.err_text = NULL;
812  estate.err_stmt = (PLpgSQL_stmt *) (func->action);
813  rc = exec_stmt_block(&estate, func->action);
814  if (rc != PLPGSQL_RC_RETURN)
815  {
816  estate.err_stmt = NULL;
817  estate.err_text = NULL;
818  ereport(ERROR,
819  (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
820  errmsg("control reached end of trigger procedure without RETURN")));
821  }
822 
823  estate.err_stmt = NULL;
824  estate.err_text = gettext_noop("during function exit");
825 
826  if (estate.retisset)
827  ereport(ERROR,
828  (errcode(ERRCODE_DATATYPE_MISMATCH),
829  errmsg("trigger procedure cannot return a set")));
830 
831  /*
832  * Check that the returned tuple structure has the same attributes, the
833  * relation that fired the trigger has. A per-statement trigger always
834  * needs to return NULL, so we ignore any return value the function itself
835  * produces (XXX: is this a good idea?)
836  *
837  * XXX This way it is possible, that the trigger returns a tuple where
838  * attributes don't have the correct atttypmod's length. It's up to the
839  * trigger's programmer to ensure that this doesn't happen. Jan
840  */
841  if (estate.retisnull || !TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
842  rettup = NULL;
843  else
844  {
845  TupleConversionMap *tupmap;
846 
847  rettup = (HeapTuple) DatumGetPointer(estate.retval);
848  /* check rowtype compatibility */
849  tupmap = convert_tuples_by_position(estate.rettupdesc,
850  trigdata->tg_relation->rd_att,
851  gettext_noop("returned row structure does not match the structure of the triggering table"));
852  /* it might need conversion */
853  if (tupmap)
854  rettup = do_convert_tuple(rettup, tupmap);
855  /* no need to free map, we're about to return anyway */
856 
857  /* Copy tuple to upper executor memory */
858  rettup = SPI_copytuple(rettup);
859  }
860 
861  /*
862  * Let the instrumentation plugin peek at this function
863  */
864  if (*plpgsql_plugin_ptr && (*plpgsql_plugin_ptr)->func_end)
865  ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
866 
867  /* Clean up any leftover temporary memory */
868  plpgsql_destroy_econtext(&estate);
869  exec_eval_cleanup(&estate);
870  /* stmt_mcontext will be destroyed when function's main context is */
871 
872  /*
873  * Pop the error context stack
874  */
875  error_context_stack = plerrcontext.previous;
876 
877  /*
878  * Return the trigger's result
879  */
880  return rettup;
881 }
TupleDesc tupdesc
Definition: plpgsql.h:308
PLpgSQL_datum ** datums
Definition: plpgsql.h:867
HeapTupleData * HeapTuple
Definition: htup.h:70
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:46
int tg_table_name_varno
Definition: plpgsql.h:848
int tg_relid_varno
Definition: plpgsql.h:846
PLpgSQL_stmt * err_stmt
Definition: plpgsql.h:932
TupleConversionMap * convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg)
Definition: tupconvert.c:66
PLpgSQL_stmt_block * action
Definition: plpgsql.h:871
#define TEXTOID
Definition: pg_type.h:324
#define PointerGetDatum(X)
Definition: postgres.h:562
bool freetup
Definition: plpgsql.h:309
static void plpgsql_exec_error_callback(void *arg)
Definition: pl_exec.c:973
int tg_table_schema_varno
Definition: plpgsql.h:849
#define Int16GetDatum(X)
Definition: postgres.h:457
#define gettext_noop(x)
Definition: c.h:139
static void plpgsql_estate_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func, ReturnSetInfo *rsi, EState *simple_eval_estate)
Definition: pl_exec.c:3395
int errcode(int sqlerrcode)
Definition: elog.c:575
static void assign_simple_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, Datum newvalue, bool isnull, bool freeable)
Definition: pl_exec.c:6902
HeapTuple SPI_copytuple(HeapTuple tuple)
Definition: spi.c:631
static void exec_eval_cleanup(PLpgSQL_execstate *estate)
Definition: pl_exec.c:3538
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
#define TRIGGER_FIRED_AFTER(event)
Definition: trigger.h:137
struct ErrorContextCallback * previous
Definition: elog.h:238
#define TRIGGER_FIRED_FOR_STATEMENT(event)
Definition: trigger.h:131
HeapTuple tg_trigtuple
Definition: trigger.h:35
PLpgSQL_datum ** datums
Definition: plpgsql.h:908
ErrorContextCallback * error_context_stack
Definition: elog.c:88
int tg_relname_varno
Definition: plpgsql.h:847
#define TRIGGER_FIRED_BY_TRUNCATE(event)
Definition: trigger.h:125
TupleDesc rettupdesc
Definition: plpgsql.h:895
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * tgname
Definition: reltrigger.h:27
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
static void plpgsql_destroy_econtext(PLpgSQL_execstate *estate)
Definition: pl_exec.c:6822
#define CStringGetDatum(X)
Definition: postgres.h:584
#define RelationGetRelationName(relation)
Definition: rel.h:436
#define ereport(elevel, rest)
Definition: elog.h:122
int SPI_register_trigger_data(TriggerData *tdata)
Definition: spi.c:2732
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:58
Oid rd_id
Definition: rel.h:116
char ** tgargs
Definition: reltrigger.h:40
#define TRIGGER_FIRED_BY_DELETE(event)
Definition: trigger.h:119
uintptr_t Datum
Definition: postgres.h:372
int tg_level_varno
Definition: plpgsql.h:844
const char * err_text
Definition: plpgsql.h:933
Trigger * tg_trigger
Definition: trigger.h:37
TupleDesc rd_att
Definition: rel.h:115
HeapTuple tg_newtuple
Definition: trigger.h:36
int tg_nargs_varno
Definition: plpgsql.h:850
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:972
static void assign_text_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, const char *str)
Definition: pl_exec.c:6937
#define Assert(condition)
Definition: c.h:664
TriggerEvent tg_event
Definition: trigger.h:33
bool freetupdesc
Definition: plpgsql.h:310
static void exec_set_found(PLpgSQL_execstate *estate, bool state)
Definition: pl_exec.c:6756
HeapTuple do_convert_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:354
#define DatumGetPointer(X)
Definition: postgres.h:555
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:134
#define TRIGGER_FIRED_INSTEAD(event)
Definition: trigger.h:140
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:116
static int exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
Definition: pl_exec.c:1177
void(* callback)(void *arg)
Definition: elog.h:239
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
HeapTuple tup
Definition: plpgsql.h:307
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:973
int i
int16 tgnargs
Definition: reltrigger.h:37
#define CStringGetTextDatum(s)
Definition: builtins.h:91
static PLpgSQL_datum * copy_plpgsql_datum(PLpgSQL_datum *datum)
Definition: pl_exec.c:1031
#define elog
Definition: elog.h:219
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3341
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:128
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:122
Relation tg_relation
Definition: trigger.h:34
#define RelationGetNamespace(relation)
Definition: rel.h:443
void plpgsql_free_function_memory ( PLpgSQL_function func)

Definition at line 695 of file pl_funcs.c.

References PLpgSQL_function::action, Assert, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_datum::dtype, elog, ERROR, PLpgSQL_function::fn_cxt, free_block(), free_expr(), i, MemoryContextDelete(), PLpgSQL_function::ndatums, PLPGSQL_DTYPE_ARRAYELEM, 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().

696 {
697  int i;
698 
699  /* Better not call this on an in-use function */
700  Assert(func->use_count == 0);
701 
702  /* Release plans associated with variable declarations */
703  for (i = 0; i < func->ndatums; i++)
704  {
705  PLpgSQL_datum *d = func->datums[i];
706 
707  switch (d->dtype)
708  {
709  case PLPGSQL_DTYPE_VAR:
710  {
711  PLpgSQL_var *var = (PLpgSQL_var *) d;
712 
713  free_expr(var->default_val);
715  }
716  break;
717  case PLPGSQL_DTYPE_ROW:
718  break;
719  case PLPGSQL_DTYPE_REC:
720  break;
722  break;
724  free_expr(((PLpgSQL_arrayelem *) d)->subscript);
725  break;
726  default:
727  elog(ERROR, "unrecognized data type: %d", d->dtype);
728  }
729  }
730  func->ndatums = 0;
731 
732  /* Release plans in statement tree */
733  if (func->action)
734  free_block(func->action);
735  func->action = NULL;
736 
737  /*
738  * And finally, release all memory except the PLpgSQL_function struct
739  * itself (which has to be kept around because there may be multiple
740  * fn_extra pointers to it).
741  */
742  if (func->fn_cxt)
744  func->fn_cxt = NULL;
745 }
PLpgSQL_datum ** datums
Definition: plpgsql.h:867
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
PLpgSQL_stmt_block * action
Definition: plpgsql.h:871
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:265
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
#define ERROR
Definition: elog.h:43
PLpgSQL_expr * default_val
Definition: plpgsql.h:264
unsigned long use_count
Definition: plpgsql.h:875
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
MemoryContext fn_cxt
Definition: plpgsql.h:827
#define Assert(condition)
Definition: c.h:664
int i
#define elog
Definition: elog.h:219
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:464
const char* plpgsql_getdiag_kindname ( PLpgSQL_getdiag_kind  kind)

Definition at line 296 of file pl_funcs.c.

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_RESULT_OID, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, PLPGSQL_GETDIAG_ROW_COUNT, PLPGSQL_GETDIAG_SCHEMA_NAME, and PLPGSQL_GETDIAG_TABLE_NAME.

Referenced by dump_getdiag().

297 {
298  switch (kind)
299  {
301  return "ROW_COUNT";
303  return "RESULT_OID";
305  return "PG_CONTEXT";
307  return "PG_EXCEPTION_CONTEXT";
309  return "PG_EXCEPTION_DETAIL";
311  return "PG_EXCEPTION_HINT";
313  return "RETURNED_SQLSTATE";
315  return "COLUMN_NAME";
317  return "CONSTRAINT_NAME";
319  return "PG_DATATYPE_NAME";
321  return "MESSAGE_TEXT";
323  return "TABLE_NAME";
325  return "SCHEMA_NAME";
326  }
327 
328  return "unknown";
329 }
void plpgsql_HashTableInit ( void  )

Definition at line 2571 of file pl_comp.c.

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

Referenced by _PG_init().

2572 {
2573  HASHCTL ctl;
2574 
2575  /* don't allow double-initialization */
2576  Assert(plpgsql_HashTable == NULL);
2577 
2578  memset(&ctl, 0, sizeof(ctl));
2579  ctl.keysize = sizeof(PLpgSQL_func_hashkey);
2580  ctl.entrysize = sizeof(plpgsql_HashEnt);
2581  plpgsql_HashTable = hash_create("PLpgSQL function cache",
2583  &ctl,
2584  HASH_ELEM | HASH_BLOBS);
2585 }
#define FUNCS_PER_USER
Definition: pl_comp.c:71
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
static HTAB * plpgsql_HashTable
Definition: pl_comp.c:63
struct plpgsql_hashent plpgsql_HashEnt
struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
Size keysize
Definition: hsearch.h:72
#define Assert(condition)
Definition: c.h:664
int plpgsql_latest_lineno ( void  )

Definition at line 688 of file pl_scanner.c.

References cur_line_num.

Referenced by plpgsql_compile_error_callback().

689 {
690  return cur_line_num;
691 }
static int cur_line_num
Definition: pl_scanner.c:232
int plpgsql_location_to_lineno ( int  location)

Definition at line 654 of file pl_scanner.c.

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

655 {
656  const char *loc;
657 
658  if (location < 0 || scanorig == NULL)
659  return 0; /* garbage in, garbage out */
660  loc = scanorig + location;
661 
662  /* be correct, but not fast, if input location goes backwards */
663  if (loc < cur_line_start)
665 
666  while (cur_line_end != NULL && loc > cur_line_end)
667  {
669  cur_line_num++;
670  cur_line_end = strchr(cur_line_start, '\n');
671  }
672 
673  return cur_line_num;
674 }
static int cur_line_num
Definition: pl_scanner.c:232
static void location_lineno_init(void)
Definition: pl_scanner.c:678
static const char * cur_line_start
Definition: pl_scanner.c:230
static const char * scanorig
Definition: pl_scanner.c:214
static const char * cur_line_end
Definition: pl_scanner.c:231
void plpgsql_ns_additem ( PLpgSQL_nsitem_type  itemtype,
int  itemno,
const char *  name 
)

Definition at line 94 of file pl_funcs.c.

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

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

95 {
96  PLpgSQL_nsitem *nse;
97 
98  Assert(name != NULL);
99  /* first item added must be a label */
100  Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
101 
102  nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
103  nse->itemtype = itemtype;
104  nse->itemno = itemno;
105  nse->prev = ns_top;
106  strcpy(nse->name, name);
107  ns_top = nse;
108 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:358
#define Assert(condition)
Definition: c.h:664
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:848
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:359
#define offsetof(type, field)
Definition: c.h:549
PLpgSQL_nsitem* plpgsql_ns_find_nearest_loop ( PLpgSQL_nsitem ns_cur)

Definition at line 216 of file pl_funcs.c.

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

217 {
218  while (ns_cur != NULL)
219  {
220  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
221  ns_cur->itemno == PLPGSQL_LABEL_LOOP)
222  return ns_cur;
223  ns_cur = ns_cur->prev;
224  }
225 
226  return NULL; /* no loop found */
227 }
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:358
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
void plpgsql_ns_init ( void  )

Definition at line 45 of file pl_funcs.c.

Referenced by do_compile(), and plpgsql_compile_inline().

46 {
47  ns_top = NULL;
48 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
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 132 of file pl_funcs.c.

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().

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

Definition at line 197 of file pl_funcs.c.

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

198 {
199  while (ns_cur != NULL)
200  {
201  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
202  strcmp(ns_cur->name, name) == 0)
203  return ns_cur;
204  ns_cur = ns_cur->prev;
205  }
206 
207  return NULL; /* label not found */
208 }
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:358
const char * name
Definition: encode.c:521
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:359
void plpgsql_ns_pop ( void  )

Definition at line 69 of file pl_funcs.c.

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

70 {
71  Assert(ns_top != NULL);
73  ns_top = ns_top->prev;
74  ns_top = ns_top->prev;
75 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:358
#define Assert(condition)
Definition: c.h:664
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
void plpgsql_ns_push ( const char *  label,
PLpgSQL_label_type  label_type 
)

Definition at line 56 of file pl_funcs.c.

References plpgsql_ns_additem(), and PLPGSQL_NSTYPE_LABEL.

Referenced by do_compile(), and plpgsql_compile_inline().

57 {
58  if (label == NULL)
59  label = "";
60  plpgsql_ns_additem(PLPGSQL_NSTYPE_LABEL, (int) label_type, label);
61 }
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:94
static char * label
Definition: pg_basebackup.c:82
PLpgSQL_nsitem* plpgsql_ns_top ( void  )

Definition at line 83 of file pl_funcs.c.

References ns_top.

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

84 {
85  return ns_top;
86 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
PLpgSQL_type* plpgsql_parse_cwordrowtype ( List idents)

Definition at line 1835 of file pl_comp.c.

References get_rel_type_id(), InvalidOid, linitial, list_length(), lsecond, makeRangeVar(), MemoryContextSwitchTo(), NoLock, plpgsql_build_datatype(), RangeVarGetRelid, and strVal.

1836 {
1837  Oid classOid;
1838  RangeVar *relvar;
1839  MemoryContext oldCxt;
1840 
1841  if (list_length(idents) != 2)
1842  return NULL;
1843 
1844  /* Avoid memory leaks in long-term function context */
1846 
1847  /* Look up relation name. Can't lock it - we might not have privileges. */
1848  relvar = makeRangeVar(strVal(linitial(idents)),
1849  strVal(lsecond(idents)),
1850  -1);
1851  classOid = RangeVarGetRelid(relvar, NoLock, false);
1852 
1853  MemoryContextSwitchTo(oldCxt);
1854 
1855  /* Build and return the row type struct */
1856  return plpgsql_build_datatype(get_rel_type_id(classOid), -1, InvalidOid);
1857 }
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2132
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define strVal(v)
Definition: value.h:54
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
#define NoLock
Definition: lockdefs.h:34
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1777
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:89
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:57
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:419
PLpgSQL_type* plpgsql_parse_cwordtype ( List idents)

Definition at line 1696 of file pl_comp.c.

References build_datatype(), elog, ERROR, GETSTRUCT, HeapTupleIsValid, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, linitial, list_length(), lsecond, lthird, makeRangeVar(), MemoryContextSwitchTo(), NoLock, ObjectIdGetDatum, OidIsValid, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_VAR, RangeVarGetRelid, ReleaseSysCache(), RELKIND_COMPOSITE_TYPE, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RelnameGetRelid(), RELOID, SearchSysCache1, SearchSysCacheAttName(), strVal, and TYPEOID.

1697 {
1698  PLpgSQL_type *dtype = NULL;
1699  PLpgSQL_nsitem *nse;
1700  const char *fldname;
1701  Oid classOid;
1702  HeapTuple classtup = NULL;
1703  HeapTuple attrtup = NULL;
1704  HeapTuple typetup = NULL;
1705  Form_pg_class classStruct;
1706  Form_pg_attribute attrStruct;
1707  MemoryContext oldCxt;
1708 
1709  /* Avoid memory leaks in the long-term function context */
1711 
1712  if (list_length(idents) == 2)
1713  {
1714  /*
1715  * Do a lookup in the current namespace stack. We don't need to check
1716  * number of names matched, because we will only consider scalar
1717  * variables.
1718  */
1719  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1720  strVal(linitial(idents)),
1721  strVal(lsecond(idents)),
1722  NULL,
1723  NULL);
1724 
1725  if (nse != NULL && nse->itemtype == PLPGSQL_NSTYPE_VAR)
1726  {
1727  dtype = ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1728  goto done;
1729  }
1730 
1731  /*
1732  * First word could also be a table name
1733  */
1734  classOid = RelnameGetRelid(strVal(linitial(idents)));
1735  if (!OidIsValid(classOid))
1736  goto done;
1737  fldname = strVal(lsecond(idents));
1738  }
1739  else if (list_length(idents) == 3)
1740  {
1741  RangeVar *relvar;
1742 
1743  relvar = makeRangeVar(strVal(linitial(idents)),
1744  strVal(lsecond(idents)),
1745  -1);
1746  /* Can't lock relation - we might not have privileges. */
1747  classOid = RangeVarGetRelid(relvar, NoLock, true);
1748  if (!OidIsValid(classOid))
1749  goto done;
1750  fldname = strVal(lthird(idents));
1751  }
1752  else
1753  goto done;
1754 
1755  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classOid));
1756  if (!HeapTupleIsValid(classtup))
1757  goto done;
1758  classStruct = (Form_pg_class) GETSTRUCT(classtup);
1759 
1760  /*
1761  * It must be a relation, sequence, view, materialized view, composite
1762  * type, or foreign table
1763  */
1764  if (classStruct->relkind != RELKIND_RELATION &&
1765  classStruct->relkind != RELKIND_SEQUENCE &&
1766  classStruct->relkind != RELKIND_VIEW &&
1767  classStruct->relkind != RELKIND_MATVIEW &&
1768  classStruct->relkind != RELKIND_COMPOSITE_TYPE &&
1769  classStruct->relkind != RELKIND_FOREIGN_TABLE &&
1770  classStruct->relkind != RELKIND_PARTITIONED_TABLE)
1771  goto done;
1772 
1773  /*
1774  * Fetch the named table field and its type
1775  */
1776  attrtup = SearchSysCacheAttName(classOid, fldname);
1777  if (!HeapTupleIsValid(attrtup))
1778  goto done;
1779  attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup);
1780 
1781  typetup = SearchSysCache1(TYPEOID,
1782  ObjectIdGetDatum(attrStruct->atttypid));
1783  if (!HeapTupleIsValid(typetup))
1784  elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid);
1785 
1786  /*
1787  * Found that - build a compiler type struct in the caller's cxt and
1788  * return it
1789  */
1790  MemoryContextSwitchTo(oldCxt);
1791  dtype = build_datatype(typetup,
1792  attrStruct->atttypmod,
1793  attrStruct->attcollation);
1795 
1796 done:
1797  if (HeapTupleIsValid(classtup))
1798  ReleaseSysCache(classtup);
1799  if (HeapTupleIsValid(attrtup))
1800  ReleaseSysCache(attrtup);
1801  if (HeapTupleIsValid(typetup))
1802  ReleaseSysCache(typetup);
1803 
1804  MemoryContextSwitchTo(oldCxt);
1805  return dtype;
1806 }
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:83
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:654
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
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:132
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define strVal(v)
Definition: value.h:54
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define lsecond(l)
Definition: pg_list.h:116
#define RELKIND_COMPOSITE_TYPE
Definition: pg_class.h:166
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:159
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
static int list_length(const List *l)
Definition: pg_list.h:89
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1205
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
static PLpgSQL_type * build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
Definition: pl_comp.c:2152
#define RELKIND_VIEW
Definition: pg_class.h:164
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:57
#define lthird(l)
Definition: pg_list.h:121
#define elog
Definition: elog.h:219
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:419
bool plpgsql_parse_dblword ( char *  word1,
char *  word2,
PLwdatum wdatum,
PLcword cword 
)

Definition at line 1416 of file pl_comp.c.

References PLwdatum::datum, PLpgSQL_row::fieldnames, i, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make2, makeString(), PLpgSQL_row::nfields, palloc(), plpgsql_adddatum(), PLPGSQL_DTYPE_RECFIELD, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_ROW, PLPGSQL_NSTYPE_VAR, pstrdup(), PLwdatum::quoted, and PLpgSQL_row::varnos.

Referenced by plpgsql_yylex().

1418 {
1419  PLpgSQL_nsitem *ns;
1420  List *idents;
1421  int nnames;
1422 
1423  idents = list_make2(makeString(word1),
1424  makeString(word2));
1425 
1426  /*
1427  * We should do nothing in DECLARE sections. In SQL expressions, we
1428  * really only need to make sure that RECFIELD datums are created when
1429  * needed.
1430  */
1432  {
1433  /*
1434  * Do a lookup in the current namespace stack
1435  */
1436  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1437  word1, word2, NULL,
1438  &nnames);
1439  if (ns != NULL)
1440  {
1441  switch (ns->itemtype)
1442  {
1443  case PLPGSQL_NSTYPE_VAR:
1444  /* Block-qualified reference to scalar variable. */
1445  wdatum->datum = plpgsql_Datums[ns->itemno];
1446  wdatum->ident = NULL;
1447  wdatum->quoted = false; /* not used */
1448  wdatum->idents = idents;
1449  return true;
1450 
1451  case PLPGSQL_NSTYPE_REC:
1452  if (nnames == 1)
1453  {
1454  /*
1455  * First word is a record name, so second word could
1456  * be a field in this record. We build a RECFIELD
1457  * datum whether it is or not --- any error will be
1458  * detected later.
1459  */
1460  PLpgSQL_recfield *new;
1461 
1462  new = palloc(sizeof(PLpgSQL_recfield));
1463  new->dtype = PLPGSQL_DTYPE_RECFIELD;
1464  new->fieldname = pstrdup(word2);
1465  new->recparentno = ns->itemno;
1466 
1468 
1469  wdatum->datum = (PLpgSQL_datum *) new;
1470  }
1471  else
1472  {
1473  /* Block-qualified reference to record variable. */
1474  wdatum->datum = plpgsql_Datums[ns->itemno];
1475  }
1476  wdatum->ident = NULL;
1477  wdatum->quoted = false; /* not used */
1478  wdatum->idents = idents;
1479  return true;
1480 
1481  case PLPGSQL_NSTYPE_ROW:
1482  if (nnames == 1)
1483  {
1484  /*
1485  * First word is a row name, so second word could be a
1486  * field in this row. Again, no error now if it
1487  * isn't.
1488  */
1489  PLpgSQL_row *row;
1490  int i;
1491 
1492  row = (PLpgSQL_row *) (plpgsql_Datums[ns->itemno]);
1493  for (i = 0; i < row->nfields; i++)
1494  {
1495  if (row->fieldnames[i] &&
1496  strcmp(row->fieldnames[i], word2) == 0)
1497  {
1498  wdatum->datum = plpgsql_Datums[row->varnos[i]];
1499  wdatum->ident = NULL;
1500  wdatum->quoted = false; /* not used */
1501  wdatum->idents = idents;
1502  return true;
1503  }
1504  }
1505  /* fall through to return CWORD */
1506  }
1507  else
1508  {
1509  /* Block-qualified reference to row variable. */
1510  wdatum->datum = plpgsql_Datums[ns->itemno];
1511  wdatum->ident = NULL;
1512  wdatum->quoted = false; /* not used */
1513  wdatum->idents = idents;
1514  return true;
1515  }
1516  break;
1517 
1518  default:
1519  break;
1520  }
1521  }
1522  }
1523 
1524  /* Nothing found */
1525  cword->idents = idents;
1526  return false;
1527 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
Value * makeString(char *str)
Definition: value.c:53
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:83
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:132
char * pstrdup(const char *in)
Definition: mcxt.c:1076
char ** fieldnames
Definition: plpgsql.h:293
List * idents
Definition: plpgsql.h:995
List * idents
Definition: plpgsql.h:1003
int * varnos
Definition: plpgsql.h:294
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:29
int nfields
Definition: plpgsql.h:292
PLpgSQL_datum * datum
Definition: plpgsql.h:1000
bool quoted
Definition: plpgsql.h:1002
char * ident
Definition: plpgsql.h:1001
void * palloc(Size size)
Definition: mcxt.c:848
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
void plpgsql_adddatum(PLpgSQL_datum *new)
Definition: pl_comp.c:2335
int i
Definition: pg_list.h:45
PLpgSQL_condition* plpgsql_parse_err_condition ( char *  condname)

Definition at line 2267 of file pl_comp.c.

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

2268 {
2269  int i;
2270  PLpgSQL_condition *new;
2271  PLpgSQL_condition *prev;
2272 
2273  /*
2274  * XXX Eventually we will want to look for user-defined exception names
2275  * here.
2276  */
2277 
2278  /*
2279  * OTHERS is represented as code 0 (which would map to '00000', but we
2280  * have no need to represent that as an exception condition).
2281  */
2282  if (strcmp(condname, "others") == 0)
2283  {
2284  new = palloc(sizeof(PLpgSQL_condition));
2285  new->sqlerrstate = 0;
2286  new->condname = condname;
2287  new->next = NULL;
2288  return new;
2289  }
2290 
2291  prev = NULL;
2292  for (i = 0; exception_label_map[i].label != NULL; i++)
2293  {
2294  if (strcmp(condname, exception_label_map[i].label) == 0)
2295  {
2296  new = palloc(sizeof(PLpgSQL_condition));
2297  new->sqlerrstate = exception_label_map[i].sqlerrstate;
2298  new->condname = condname;
2299  new->next = prev;
2300  prev = new;
2301  }
2302  }
2303 
2304  if (!prev)
2305  ereport(ERROR,
2306  (errcode(ERRCODE_UNDEFINED_OBJECT),
2307  errmsg("unrecognized exception condition \"%s\"",
2308  condname)));
2309 
2310  return prev;
2311 }
const char * label
Definition: pl_comp.c:79
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static char * label
Definition: pg_basebackup.c:82
static const ExceptionLabelMap exception_label_map[]
Definition: pl_comp.c:83
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
bool plpgsql_parse_tripword ( char *  word1,
char *  word2,
char *  word3,
PLwdatum wdatum,
PLcword cword 
)

Definition at line 1536 of file pl_comp.c.

References PLwdatum::datum, PLpgSQL_row::fieldnames, i, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make3, makeString(), PLpgSQL_row::nfields, palloc(), plpgsql_adddatum(), PLPGSQL_DTYPE_RECFIELD, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_ROW, pstrdup(), PLwdatum::quoted, and PLpgSQL_row::varnos.

Referenced by plpgsql_yylex().

1538 {
1539  PLpgSQL_nsitem *ns;
1540  List *idents;
1541  int nnames;
1542 
1543  idents = list_make3(makeString(word1),
1544  makeString(word2),
1545  makeString(word3));
1546 
1547  /*
1548  * We should do nothing in DECLARE sections. In SQL expressions, we
1549  * really only need to make sure that RECFIELD datums are created when
1550  * needed.
1551  */
1553  {
1554  /*
1555  * Do a lookup in the current namespace stack. Must find a qualified
1556  * reference, else ignore.
1557  */
1558  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1559  word1, word2, word3,
1560  &nnames);
1561  if (ns != NULL && nnames == 2)
1562  {
1563  switch (ns->itemtype)
1564  {
1565  case PLPGSQL_NSTYPE_REC:
1566  {
1567  /*
1568  * words 1/2 are a record name, so third word could be
1569  * a field in this record.
1570  */
1571  PLpgSQL_recfield *new;
1572 
1573  new = palloc(sizeof(PLpgSQL_recfield));
1574  new->dtype = PLPGSQL_DTYPE_RECFIELD;
1575  new->fieldname = pstrdup(word3);
1576  new->recparentno = ns->itemno;
1577 
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  case PLPGSQL_NSTYPE_ROW:
1588  {
1589  /*
1590  * words 1/2 are a row name, so third word could be a
1591  * field in this row.
1592  */
1593  PLpgSQL_row *row;
1594  int i;
1595 
1596  row = (PLpgSQL_row *) (plpgsql_Datums[ns->itemno]);
1597  for (i = 0; i < row->nfields; i++)
1598  {
1599  if (row->fieldnames[i] &&
1600  strcmp(row->fieldnames[i], word3) == 0)
1601  {
1602  wdatum->datum = plpgsql_Datums[row->varnos[i]];
1603  wdatum->ident = NULL;
1604  wdatum->quoted = false; /* not used */
1605  wdatum->idents = idents;
1606  return true;
1607  }
1608  }
1609  /* fall through to return CWORD */
1610  break;
1611  }
1612 
1613  default:
1614  break;
1615  }
1616  }
1617  }
1618 
1619  /* Nothing found */
1620  cword->idents = idents;
1621  return false;
1622 }
Value * makeString(char *str)
Definition: value.c:53
#define list_make3(x1, x2, x3)
Definition: pg_list.h:141
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:83
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:132
char * pstrdup(const char *in)
Definition: mcxt.c:1076
char ** fieldnames
Definition: plpgsql.h:293
List * idents
Definition: plpgsql.h:995
List * idents
Definition: plpgsql.h:1003
int * varnos
Definition: plpgsql.h:294
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:29
int nfields
Definition: plpgsql.h:292
PLpgSQL_datum * datum
Definition: plpgsql.h:1000
bool quoted
Definition: plpgsql.h:1002
char * ident
Definition: plpgsql.h:1001
void * palloc(Size size)
Definition: mcxt.c:848
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
void plpgsql_adddatum(PLpgSQL_datum *new)
Definition: pl_comp.c:2335
int i
Definition: pg_list.h:45
bool plpgsql_parse_word ( char *  word1,
const char *  yytxt,
PLwdatum wdatum,
PLword word 
)

Definition at line 1360 of file pl_comp.c.

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

Referenced by plpgsql_yylex().

1362 {
1363  PLpgSQL_nsitem *ns;
1364 
1365  /*
1366  * We should do nothing in DECLARE sections. In SQL expressions, there's
1367  * no need to do anything either --- lookup will happen when the
1368  * expression is compiled.
1369  */
1371  {
1372  /*
1373  * Do a lookup in the current namespace stack
1374  */
1375  ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1376  word1, NULL, NULL,
1377  NULL);
1378 
1379  if (ns != NULL)
1380  {
1381  switch (ns->itemtype)
1382  {
1383  case PLPGSQL_NSTYPE_VAR:
1384  case PLPGSQL_NSTYPE_ROW:
1385  case PLPGSQL_NSTYPE_REC:
1386  wdatum->datum = plpgsql_Datums[ns->itemno];
1387  wdatum->ident = word1;
1388  wdatum->quoted = (yytxt[0] == '"');
1389  wdatum->idents = NIL;
1390  return true;
1391 
1392  default:
1393  /* plpgsql_ns_lookup should never return anything else */
1394  elog(ERROR, "unrecognized plpgsql itemtype: %d",
1395  ns->itemtype);
1396  }
1397  }
1398  }
1399 
1400  /*
1401  * Nothing found - up to now it's a word without any special meaning for
1402  * us.
1403  */
1404  word->ident = word1;
1405  word->quoted = (yytxt[0] == '"');
1406  return false;
1407 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:83
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:132
char * ident
Definition: plpgsql.h:989
#define ERROR
Definition: elog.h:43
List * idents
Definition: plpgsql.h:1003
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:29
bool quoted
Definition: plpgsql.h:990
PLpgSQL_datum * datum
Definition: plpgsql.h:1000
bool quoted
Definition: plpgsql.h:1002
char * ident
Definition: plpgsql.h:1001
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
#define elog
Definition: elog.h:219
PLpgSQL_type* plpgsql_parse_wordrowtype ( char *  ident)

Definition at line 1814 of file pl_comp.c.

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

1815 {
1816  Oid classOid;
1817 
1818  /* Lookup the relation */
1819  classOid = RelnameGetRelid(ident);
1820  if (!OidIsValid(classOid))
1821  ereport(ERROR,
1823  errmsg("relation \"%s\" does not exist", ident)));
1824 
1825  /* Build and return the row type struct */
1826  return plpgsql_build_datatype(get_rel_type_id(classOid), -1, InvalidOid);
1827 }
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2132
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:61
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:654
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1777
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:797
PLpgSQL_type* plpgsql_parse_wordtype ( char *  ident)

Definition at line 1633 of file pl_comp.c.

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

1634 {
1635  PLpgSQL_type *dtype;
1636  PLpgSQL_nsitem *nse;
1637  HeapTuple typeTup;
1638 
1639  /*
1640  * Do a lookup in the current namespace stack
1641  */
1642  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1643  ident, NULL, NULL,
1644  NULL);
1645 
1646  if (nse != NULL)
1647  {
1648  switch (nse->itemtype)
1649  {
1650  case PLPGSQL_NSTYPE_VAR:
1651  return ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1652 
1653  /* XXX perhaps allow REC/ROW here? */
1654 
1655  default:
1656  return NULL;
1657  }
1658  }
1659 
1660  /*
1661  * Word wasn't found in the namespace stack. Try to find a data type with
1662  * that name, but ignore shell types and complex types.
1663  */
1664  typeTup = LookupTypeName(NULL, makeTypeName(ident), NULL, false);
1665  if (typeTup)
1666  {
1667  Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
1668 
1669  if (!typeStruct->typisdefined ||
1670  typeStruct->typrelid != InvalidOid)
1671  {
1672  ReleaseSysCache(typeTup);
1673  return NULL;
1674  }
1675 
1676  dtype = build_datatype(typeTup, -1,
1678 
1679  ReleaseSysCache(typeTup);
1680  return dtype;
1681  }
1682 
1683  /*
1684  * Nothing found - up to now it's a word without any special meaning for
1685  * us.
1686  */
1687  return NULL;
1688 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:57
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:47
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:83
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
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:132
FormData_pg_type * Form_pg_type
Definition: pg_type.h:233
Oid fn_input_collation
Definition: plpgsql.h:825
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
TypeName * makeTypeName(char *typnam)
Definition: makefuncs.c:441
static PLpgSQL_type * build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
Definition: pl_comp.c:2152
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
PLpgSQL_function * plpgsql_curr_compile
Definition: pl_comp.c:54
void plpgsql_parser_setup ( struct ParseState pstate,
PLpgSQL_expr expr 
)

Definition at line 1023 of file pl_comp.c.

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(), plpgsql_estate_setup(), and setup_unshared_param_list().

1024 {
1028  /* no need to use p_coerce_param_hook */
1029  pstate->p_ref_hook_state = (void *) expr;
1030 }
static Node * plpgsql_pre_column_ref(ParseState *pstate, ColumnRef *cref)
Definition: pl_comp.c:1036
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:211
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:212
static Node * plpgsql_param_ref(ParseState *pstate, ParamRef *pref)
Definition: pl_comp.c:1094
void * p_ref_hook_state
Definition: parse_node.h:214
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:210
static Node * plpgsql_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var)
Definition: pl_comp.c:1050
int plpgsql_peek ( void  )

Definition at line 536 of file pl_scanner.c.

References internal_yylex(), and push_back_token().

537 {
538  int tok1;
539  TokenAuxData aux1;
540 
541  tok1 = internal_yylex(&aux1);
542  push_back_token(tok1, &aux1);
543  return tok1;
544 }
static int internal_yylex(TokenAuxData *auxdata)
Definition: pl_scanner.c:424
static void push_back_token(int token, TokenAuxData *auxdata)
Definition: pl_scanner.c:470
void plpgsql_peek2 ( int *  tok1_p,
int *  tok2_p,
int *  tok1_loc,
int *  tok2_loc 
)

Definition at line 555 of file pl_scanner.c.

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

556 {
557  int tok1,
558  tok2;
559  TokenAuxData aux1,
560  aux2;
561 
562  tok1 = internal_yylex(&aux1);
563  tok2 = internal_yylex(&aux2);
564 
565  *tok1_p = tok1;
566  if (tok1_loc)
567  *tok1_loc = aux1.lloc;
568  *tok2_p = tok2;
569  if (tok2_loc)
570  *tok2_loc = aux2.lloc;
571 
572  push_back_token(tok2, &aux2);
573  push_back_token(tok1, &aux1);
574 }
YYLTYPE lloc
Definition: pl_scanner.c:198
static int internal_yylex(TokenAuxData *auxdata)
Definition: pl_scanner.c:424
static void push_back_token(int token, TokenAuxData *auxdata)
Definition: pl_scanner.c:470
void plpgsql_push_back_token ( int  token)

Definition at line 486 of file pl_scanner.c.

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

487 {
488  TokenAuxData auxdata;
489 
490  auxdata.lval = plpgsql_yylval;
491  auxdata.lloc = plpgsql_yylloc;
492  auxdata.leng = plpgsql_yyleng;
493  push_back_token(token, &auxdata);
494 }
YYLTYPE lloc
Definition: pl_scanner.c:198
YYSTYPE lval
Definition: pl_scanner.c:197
static int plpgsql_yyleng
Definition: pl_scanner.c:217
static void push_back_token(int token, TokenAuxData *auxdata)
Definition: pl_scanner.c:470
int plpgsql_recognize_err_condition ( const char *  condname,
bool  allow_sqlstate 
)

Definition at line 2231 of file pl_comp.c.

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

Referenced by exec_stmt_raise().

2232 {
2233  int i;
2234 
2235  if (allow_sqlstate)
2236  {
2237  if (strlen(condname) == 5 &&
2238  strspn(condname, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
2239  return MAKE_SQLSTATE(condname[0],
2240  condname[1],
2241  condname[2],
2242  condname[3],
2243  condname[4]);
2244  }
2245 
2246  for (i = 0; exception_label_map[i].label != NULL; i++)
2247  {
2248  if (strcmp(condname, exception_label_map[i].label) == 0)
2250  }
2251 
2252  ereport(ERROR,
2253  (errcode(ERRCODE_UNDEFINED_OBJECT),
2254  errmsg("unrecognized exception condition \"%s\"",
2255  condname)));
2256  return 0; /* keep compiler quiet */
2257 }
const char * label
Definition: pl_comp.c:79
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:62
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static char * label
Definition: pg_basebackup.c:82
static const ExceptionLabelMap exception_label_map[]
Definition: pl_comp.c:83
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int plpgsql_scanner_errposition ( int  location)

Definition at line 588 of file pl_scanner.c.

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

Referenced by plpgsql_yyerror().

589 {
590  int pos;
591 
592  if (location < 0 || scanorig == NULL)
593  return 0; /* no-op if location is unknown */
594 
595  /* Convert byte offset to character number */
596  pos = pg_mbstrlen_with_len(scanorig, location) + 1;
597  /* And pass it to the ereport mechanism */
598  (void) internalerrposition(pos);
599  /* Also pass the function body string */
600  return internalerrquery(scanorig);
601 }
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:805
static const char * scanorig
Definition: pl_scanner.c:214
int internalerrquery(const char *query)
Definition: elog.c:1161
int internalerrposition(int cursorpos)
Definition: elog.c:1141
void plpgsql_scanner_finish ( void  )

Definition at line 729 of file pl_scanner.c.

References scanner_finish(), scanorig, and yyscanner.

Referenced by do_compile(), and plpgsql_compile_inline().

730 {
731  /* release storage */
733  /* avoid leaving any dangling pointers */
734  yyscanner = NULL;
735  scanorig = NULL;
736 }
static const char * scanorig
Definition: pl_scanner.c:214
static core_yyscan_t yyscanner
Definition: pl_scanner.c:210
void scanner_finish(core_yyscan_t yyscanner)
void plpgsql_scanner_init ( const char *  str)

Definition at line 702 of file pl_scanner.c.

References IDENTIFIER_LOOKUP_NORMAL, location_lineno_init(), num_pushbacks, num_reserved_keywords, plpgsql_IdentifierLookup, plpgsql_yytoken, scanner_init(), scanorig, and yyscanner.

Referenced by do_compile(), and plpgsql_compile_inline().

703 {
704  /* Start up the core scanner */
707 
708  /*
709  * scanorig points to the original string, which unlike the scanner's
710  * scanbuf won't be modified on-the-fly by flex. Notice that although
711  * yytext points into scanbuf, we rely on being able to apply locations
712  * (offsets from string start) to scanorig as well.
713  */
714  scanorig = str;
715 
716  /* Other setup */
718  plpgsql_yytoken = 0;
719 
720  num_pushbacks = 0;
721 
723 }
static const ScanKeyword reserved_keywords[]
Definition: pl_scanner.c:70
static void location_lineno_init(void)
Definition: pl_scanner.c:678
static int plpgsql_yytoken
Definition: pl_scanner.c:220
static const char * scanorig
Definition: pl_scanner.c:214
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:29
static int num_pushbacks
Definition: pl_scanner.c:225
static core_yy_extra_type core_yy
Definition: pl_scanner.c:211
core_yyscan_t scanner_init(const char *str, core_yy_extra_type *yyext, const ScanKeyword *keywords, int num_keywords)
static core_yyscan_t yyscanner
Definition: pl_scanner.c:210
static const int num_reserved_keywords
Definition: pl_scanner.c:97
const char* plpgsql_stmt_typename ( PLpgSQL_stmt stmt)

Definition at line 234 of file pl_funcs.c.

References _, PLpgSQL_stmt::cmd_type, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, 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, and PLPGSQL_STMT_WHILE.

Referenced by plpgsql_exec_error_callback().

235 {
236  switch (stmt->cmd_type)
237  {
238  case PLPGSQL_STMT_BLOCK:
239  return _("statement block");
240  case PLPGSQL_STMT_ASSIGN:
241  return _("assignment");
242  case PLPGSQL_STMT_IF:
243  return "IF";
244  case PLPGSQL_STMT_CASE:
245  return "CASE";
246  case PLPGSQL_STMT_LOOP:
247  return "LOOP";
248  case PLPGSQL_STMT_WHILE:
249  return "WHILE";
250  case PLPGSQL_STMT_FORI:
251  return _("FOR with integer loop variable");
252  case PLPGSQL_STMT_FORS:
253  return _("FOR over SELECT rows");
254  case PLPGSQL_STMT_FORC:
255  return _("FOR over cursor");
257  return _("FOREACH over array");
258  case PLPGSQL_STMT_EXIT:
259  return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
260  case PLPGSQL_STMT_RETURN:
261  return "RETURN";
263  return "RETURN NEXT";
265  return "RETURN QUERY";
266  case PLPGSQL_STMT_RAISE:
267  return "RAISE";
268  case PLPGSQL_STMT_ASSERT:
269  return "ASSERT";
271  return _("SQL statement");
273  return "EXECUTE";
275  return _("FOR over EXECUTE statement");
277  return ((PLpgSQL_stmt_getdiag *) stmt)->is_stacked ?
278  "GET STACKED DIAGNOSTICS" : "GET DIAGNOSTICS";
279  case PLPGSQL_STMT_OPEN:
280  return "OPEN";
281  case PLPGSQL_STMT_FETCH:
282  return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
283  case PLPGSQL_STMT_CLOSE:
284  return "CLOSE";
286  return "PERFORM";
287  }
288 
289  return "unknown";
290 }
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:367
#define _(x)
Definition: elog.c:84
void plpgsql_subxact_cb ( SubXactEvent  event,
SubTransactionId  mySubid,
SubTransactionId  parentSubid,
void *  arg 
)

Definition at line 6876 of file pl_exec.c.

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

Referenced by _PG_init(), and plpgsql_inline_handler().

6878 {
6879  if (event == SUBXACT_EVENT_COMMIT_SUB || event == SUBXACT_EVENT_ABORT_SUB)
6880  {
6881  while (simple_econtext_stack != NULL &&
6882  simple_econtext_stack->xact_subxid == mySubid)
6883  {
6885 
6887  (event == SUBXACT_EVENT_COMMIT_SUB));
6888  next = simple_econtext_stack->next;
6891  }
6892  }
6893 }
static int32 next
Definition: blutils.c:210
struct SimpleEcontextStackEntry * next
Definition: pl_exec.c:85
void pfree(void *pointer)
Definition: mcxt.c:949
ExprContext * stack_econtext
Definition: pl_exec.c:83
static SimpleEcontextStackEntry * simple_econtext_stack
Definition: pl_exec.c:89
SubTransactionId xact_subxid
Definition: pl_exec.c:84
void FreeExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:354
bool plpgsql_token_is_unreserved_keyword ( int  token)

Definition at line 503 of file pl_scanner.c.

References i, num_unreserved_keywords, and value.

504 {
505  int i;
506 
507  for (i = 0; i < num_unreserved_keywords; i++)
508  {
509  if (unreserved_keywords[i].value == token)
510  return true;
511  }
512  return false;
513 }
static const int num_unreserved_keywords
Definition: pl_scanner.c:178
static struct @121 value
static const ScanKeyword unreserved_keywords[]
Definition: pl_scanner.c:99
int i
void plpgsql_xact_cb ( XactEvent  event,
void *  arg 
)

Definition at line 6844 of file pl_exec.c.

References Assert, FreeExecutorState(), XACT_EVENT_ABORT, XACT_EVENT_COMMIT, and XACT_EVENT_PREPARE.

Referenced by _PG_init().

6845 {
6846  /*
6847  * If we are doing a clean transaction shutdown, free the EState (so that
6848  * any remaining resources will be released correctly). In an abort, we
6849  * expect the regular abort recovery procedures to release everything of
6850  * interest.
6851  */
6852  if (event == XACT_EVENT_COMMIT || event == XACT_EVENT_PREPARE)
6853  {
6854  /* Shouldn't be any econtext stack entries left at commit */
6855  Assert(simple_econtext_stack == NULL);
6856 
6860  }
6861  else if (event == XACT_EVENT_ABORT)
6862  {
6863  simple_econtext_stack = NULL;
6865  }
6866 }
void FreeExecutorState(EState *estate)
Definition: execUtils.c:183
static SimpleEcontextStackEntry * simple_econtext_stack
Definition: pl_exec.c:89
static EState * shared_simple_eval_estate
Definition: pl_exec.c:88
#define Assert(condition)
Definition: c.h:664
void plpgsql_yyerror ( const char *  message)

Definition at line 615 of file pl_scanner.c.

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

616 {
617  char *yytext = core_yy.scanbuf + plpgsql_yylloc;
618 
619  if (*yytext == '\0')
620  {
621  ereport(ERROR,
622  (errcode(ERRCODE_SYNTAX_ERROR),
623  /* translator: %s is typically the translation of "syntax error" */
624  errmsg("%s at end of input", _(message)),
625  plpgsql_scanner_errposition(plpgsql_yylloc)));
626  }
627  else
628  {
629  /*
630  * If we have done any lookahead then flex will have restored the
631  * character after the end-of-token. Zap it again so that we report
632  * only the single token here. This modifies scanbuf but we no longer
633  * care about that.
634  */
635  yytext[plpgsql_yyleng] = '\0';
636 
637  ereport(ERROR,
638  (errcode(ERRCODE_SYNTAX_ERROR),
639  /* translator: first %s is typically the translation of "syntax error" */
640  errmsg("%s at or near \"%s\"", _(message), yytext),
641  plpgsql_scanner_errposition(plpgsql_yylloc)));
642  }
643 }
int errcode(int sqlerrcode)
Definition: elog.c:575
char * scanbuf
Definition: scanner.h:72
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static core_yy_extra_type core_yy
Definition: pl_scanner.c:211
static int plpgsql_yyleng
Definition: pl_scanner.c:217
int plpgsql_scanner_errposition(int location)
Definition: pl_scanner.c:588
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define _(x)
Definition: elog.c:84
int plpgsql_yylex ( void  )

Definition at line 250 of file pl_scanner.c.

References AT_STMT_START, internal_yylex(), TokenAuxData::leng, TokenAuxData::lloc, TokenAuxData::lval, ScanKeyword::name, num_unreserved_keywords, plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_yyleng, plpgsql_yytoken, push_back_token(), core_yy_extra_type::scanbuf, ScanKeywordLookup(), and ScanKeyword::value.

251 {
252  int tok1;
253  TokenAuxData aux1;
254  const ScanKeyword *kw;
255 
256  tok1 = internal_yylex(&aux1);
257  if (tok1 == IDENT || tok1 == PARAM)
258  {
259  int tok2;
260  TokenAuxData aux2;
261 
262  tok2 = internal_yylex(&aux2);
263  if (tok2 == '.')
264  {
265  int tok3;
266  TokenAuxData aux3;
267 
268  tok3 = internal_yylex(&aux3);
269  if (tok3 == IDENT)
270  {
271  int tok4;
272  TokenAuxData aux4;
273 
274  tok4 = internal_yylex(&aux4);
275  if (tok4 == '.')
276  {
277  int tok5;
278  TokenAuxData aux5;
279 
280  tok5 = internal_yylex(&aux5);
281  if (tok5 == IDENT)
282  {
283  if (plpgsql_parse_tripword(aux1.lval.str,
284  aux3.lval.str,
285  aux5.lval.str,
286  &aux1.lval.wdatum,
287  &aux1.lval.cword))
288  tok1 = T_DATUM;
289  else
290  tok1 = T_CWORD;
291  }
292  else
293  {
294  /* not A.B.C, so just process A.B */
295  push_back_token(tok5, &aux5);
296  push_back_token(tok4, &aux4);
297  if (plpgsql_parse_dblword(aux1.lval.str,
298  aux3.lval.str,
299  &aux1.lval.wdatum,
300  &aux1.lval.cword))
301  tok1 = T_DATUM;
302  else
303  tok1 = T_CWORD;
304  }
305  }
306  else
307  {
308  /* not A.B.C, so just process A.B */
309  push_back_token(tok4, &aux4);
310  if (plpgsql_parse_dblword(aux1.lval.str,
311  aux3.lval.str,
312  &aux1.lval.wdatum,
313  &aux1.lval.cword))
314  tok1 = T_DATUM;
315  else
316  tok1 = T_CWORD;
317  }
318  }
319  else
320  {
321  /* not A.B, so just process A */
322  push_back_token(tok3, &aux3);
323  push_back_token(tok2, &aux2);
324  if (plpgsql_parse_word(aux1.lval.str,
325  core_yy.scanbuf + aux1.lloc,
326  &aux1.lval.wdatum,
327  &aux1.lval.word))
328  tok1 = T_DATUM;
329  else if (!aux1.lval.word.quoted &&
330  (kw = ScanKeywordLookup(aux1.lval.word.ident,
333  {
334  aux1.lval.keyword = kw->name;
335  tok1 = kw->value;
336  }
337  else
338  tok1 = T_WORD;
339  }
340  }
341  else
342  {
343  /* not A.B, so just process A */
344  push_back_token(tok2, &aux2);
345 
346  /*
347  * If we are at start of statement, prefer unreserved keywords
348  * over variable names, unless the next token is assignment or
349  * '[', in which case prefer variable names. (Note we need not
350  * consider '.' as the next token; that case was handled above,
351  * and we always prefer variable names in that case.) If we are
352  * not at start of statement, always prefer variable names over
353  * unreserved keywords.
354  */
356  !(tok2 == '=' || tok2 == COLON_EQUALS || tok2 == '['))
357  {
358  /* try for unreserved keyword, then for variable name */
359  if (core_yy.scanbuf[aux1.lloc] != '"' &&
360  (kw =