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

Referenced by plpgsql_extra_checks_check_hook().

#define PLPGSQL_XCHECK_NONE   0

Definition at line 1025 of file plpgsql.h.

Referenced by plpgsql_extra_checks_check_hook().

#define PLPGSQL_XCHECK_SHADOWVAR   1

Definition at line 1026 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 1009 of file plpgsql.h.

1010 {
1011  IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
1012  IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
1013  IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
IdentifierLookup
Definition: plpgsql.h:1009
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 807 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:7731
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
#define NULL
Definition: c.h:229
static int auth_delay_milliseconds
Definition: auth_delay.c:26
#define GUC_UNIT_MS
Definition: guc.h:224
int plpgsql_add_initdatums ( int **  varnos)

Definition at line 2389 of file pl_comp.c.

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

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

Definition at line 2328 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().

2329 {
2331  {
2332  datums_alloc *= 2;
2334  }
2335 
2336  new->dno = plpgsql_nDatums;
2338 }
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:963
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:675
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:240
int plpgsql_base_yylex ( void  )
PLpgSQL_type* plpgsql_build_datatype ( Oid  typeOid,
int32  typmod,
Oid  collation 
)

Definition at line 2125 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().

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

Definition at line 1943 of file pl_comp.c.

References PLpgSQL_rec::dno, PLpgSQL_rec::dtype, PLpgSQL_rec::freetup, PLpgSQL_rec::freetupdesc, PLpgSQL_rec::lineno, NULL, 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().

1944 {
1945  PLpgSQL_rec *rec;
1946 
1947  rec = palloc0(sizeof(PLpgSQL_rec));
1948  rec->dtype = PLPGSQL_DTYPE_REC;
1949  rec->refname = pstrdup(refname);
1950  rec->lineno = lineno;
1951  rec->tup = NULL;
1952  rec->tupdesc = NULL;
1953  rec->freetup = false;
1954  rec->freetupdesc = false;
1956  if (add2namespace)
1958 
1959  return rec;
1960 }
PLpgSQL_datum_type dtype
Definition: plpgsql.h:302
TupleDesc tupdesc
Definition: plpgsql.h:308
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:878
#define NULL
Definition: c.h:229
bool freetupdesc
Definition: plpgsql.h:310
HeapTuple tup
Definition: plpgsql.h:307
void plpgsql_adddatum(PLpgSQL_datum *new)
Definition: pl_comp.c:2328
int lineno
Definition: plpgsql.h:305
PLpgSQL_variable* plpgsql_build_variable ( const char *  refname,
int  lineno,
PLpgSQL_type dtype,
bool  add2namespace 
)

Definition at line 1863 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, NULL, 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().

1865 {
1867 
1868  switch (dtype->ttype)
1869  {
1870  case PLPGSQL_TTYPE_SCALAR:
1871  {
1872  /* Ordinary scalar datatype */
1873  PLpgSQL_var *var;
1874 
1875  var = palloc0(sizeof(PLpgSQL_var));
1876  var->dtype = PLPGSQL_DTYPE_VAR;
1877  var->refname = pstrdup(refname);
1878  var->lineno = lineno;
1879  var->datatype = dtype;
1880  /* other fields might be filled by caller */
1881 
1882  /* preset to NULL */
1883  var->value = 0;
1884  var->isnull = true;
1885  var->freeval = false;
1886 
1888  if (add2namespace)
1890  var->dno,
1891  refname);
1892  result = (PLpgSQL_variable *) var;
1893  break;
1894  }
1895  case PLPGSQL_TTYPE_ROW:
1896  {
1897  /* Composite type -- build a row variable */
1898  PLpgSQL_row *row;
1899 
1900  row = build_row_from_class(dtype->typrelid);
1901 
1902  row->dtype = PLPGSQL_DTYPE_ROW;
1903  row->refname = pstrdup(refname);
1904  row->lineno = lineno;
1905 
1907  if (add2namespace)
1909  row->dno,
1910  refname);
1911  result = (PLpgSQL_variable *) row;
1912  break;
1913  }
1914  case PLPGSQL_TTYPE_REC:
1915  {
1916  /* "record" type -- build a record variable */
1917  PLpgSQL_rec *rec;
1918 
1919  rec = plpgsql_build_record(refname, lineno, add2namespace);
1920  result = (PLpgSQL_variable *) rec;
1921  break;
1922  }
1923  case PLPGSQL_TTYPE_PSEUDO:
1924  ereport(ERROR,
1925  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1926  errmsg("variable \"%s\" has pseudo-type %s",
1927  refname, format_type_be(dtype->typoid))));
1928  result = NULL; /* keep compiler quiet */
1929  break;
1930  default:
1931  elog(ERROR, "unrecognized ttype: %d", dtype->ttype);
1932  result = NULL; /* keep compiler quiet */
1933  break;
1934  }
1935 
1936  return result;
1937 }
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:1966
PLpgSQL_datum_type dtype
Definition: plpgsql.h:256
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:1943
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:1618
#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:878
Datum value
Definition: plpgsql.h:269
#define NULL
Definition: c.h:229
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:2328
#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(), NULL, 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:2441
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
HeapTupleHeader t_data
Definition: htup.h:67
static void delete_function(PLpgSQL_function *func)
Definition: pl_comp.c:2551
FmgrInfo * flinfo
Definition: fmgr.h:79
static PLpgSQL_function * plpgsql_HashTableLookup(PLpgSQL_func_hashkey *func_key)
Definition: pl_comp.c:2580
#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:1116
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 NULL
Definition: c.h:229
#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 794 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(), NULL, 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().

795 {
796  char *func_name = "inline_code_block";
797  PLpgSQL_function *function;
798  ErrorContextCallback plerrcontext;
799  PLpgSQL_variable *var;
800  int parse_rc;
801  MemoryContext func_cxt;
802 
803  /*
804  * Setup the scanner input and error info. We assume that this function
805  * cannot be invoked recursively, so there's no need to save and restore
806  * the static variables used here.
807  */
808  plpgsql_scanner_init(proc_source);
809 
810  plpgsql_error_funcname = func_name;
811 
812  /*
813  * Setup error traceback support for ereport()
814  */
816  plerrcontext.arg = proc_source;
817  plerrcontext.previous = error_context_stack;
818  error_context_stack = &plerrcontext;
819 
820  /* Do extra syntax checking if check_function_bodies is on */
822 
823  /* Function struct does not live past current statement */
824  function = (PLpgSQL_function *) palloc0(sizeof(PLpgSQL_function));
825 
826  plpgsql_curr_compile = function;
827 
828  /*
829  * All the rest of the compile-time storage (e.g. parse tree) is kept in
830  * its own memory context, so it can be reclaimed easily.
831  */
833  "PL/pgSQL inline code context",
836 
837  function->fn_signature = pstrdup(func_name);
838  function->fn_is_trigger = PLPGSQL_NOT_TRIGGER;
839  function->fn_input_collation = InvalidOid;
840  function->fn_cxt = func_cxt;
841  function->out_param_varno = -1; /* set up for no OUT param */
842  function->resolve_option = plpgsql_variable_conflict;
843  function->print_strict_params = plpgsql_print_strict_params;
844 
845  /*
846  * don't do extra validation for inline code as we don't want to add spam
847  * at runtime
848  */
849  function->extra_warnings = 0;
850  function->extra_errors = 0;
851 
852  plpgsql_ns_init();
854  plpgsql_DumpExecTree = false;
856 
857  /* Set up as though in a function returning VOID */
858  function->fn_rettype = VOIDOID;
859  function->fn_retset = false;
860  function->fn_retistuple = false;
861  /* a bit of hardwired knowledge about type VOID here */
862  function->fn_retbyval = true;
863  function->fn_rettyplen = sizeof(int32);
864 
865  /*
866  * Remember if function is STABLE/IMMUTABLE. XXX would it be better to
867  * set this TRUE inside a read-only transaction? Not clear.
868  */
869  function->fn_readonly = false;
870 
871  /*
872  * Create the magic FOUND variable.
873  */
874  var = plpgsql_build_variable("found", 0,
876  -1,
877  InvalidOid),
878  true);
879  function->found_varno = var->dno;
880 
881  /*
882  * Now parse the function's text
883  */
884  parse_rc = plpgsql_yyparse();
885  if (parse_rc != 0)
886  elog(ERROR, "plpgsql parser returned %d", parse_rc);
887  function->action = plpgsql_parse_result;
888 
890 
891  /*
892  * If it returns VOID (always true at the moment), we allow control to
893  * fall off the end without an explicit RETURN statement.
894  */
895  if (function->fn_rettype == VOIDOID)
896  add_dummy_return(function);
897 
898  /*
899  * Complete the function's info
900  */
901  function->fn_nargs = 0;
902 
903  plpgsql_finish_datums(function);
904 
905  /*
906  * Pop the error context stack
907  */
908  error_context_stack = plerrcontext.previous;
910 
911  plpgsql_check_syntax = false;
912 
915  return function;
916 }
int plpgsql_yyparse(void)
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2125
char * pstrdup(const char *in)
Definition: mcxt.c:1077
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool check_function_bodies
Definition: guc.c:450
struct ErrorContextCallback * previous
Definition: elog.h:238
static void plpgsql_start_datums(void)
Definition: pl_comp.c:2311
signed int int32
Definition: c.h:256
ErrorContextCallback * error_context_stack
Definition: elog.c:88
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:729
#define VOIDOID
Definition: pg_type.h:686
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:977
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:878
#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:925
int plpgsql_variable_conflict
Definition: pl_handler.c:46
#define NULL
Definition: c.h:229
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:1863
#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:2348
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, NULL, 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:866
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:870
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
#define NULL
Definition: c.h:229
int nfields
Definition: plpgsql.h:292
static int dump_indent
Definition: pl_funcs.c:751
char * fn_signature
Definition: plpgsql.h:819
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 886 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, NULL, 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().

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

Definition at line 330 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, NULL, 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().

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

4936 {
4937  Oid typeid;
4938 
4939  switch (datum->dtype)
4940  {
4941  case PLPGSQL_DTYPE_VAR:
4942  {
4943  PLpgSQL_var *var = (PLpgSQL_var *) datum;
4944 
4945  typeid = var->datatype->typoid;
4946  break;
4947  }
4948 
4949  case PLPGSQL_DTYPE_ROW:
4950  {
4951  PLpgSQL_row *row = (PLpgSQL_row *) datum;
4952 
4953  if (!row->rowtupdesc) /* should not happen */
4954  elog(ERROR, "row variable has no tupdesc");
4955  /* Make sure we have a valid type/typmod setting */
4956  BlessTupleDesc(row->rowtupdesc);
4957  typeid = row->rowtupdesc->tdtypeid;
4958  break;
4959  }
4960 
4961  case PLPGSQL_DTYPE_REC:
4962  {
4963  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
4964 
4965  if (rec->tupdesc == NULL)
4966  ereport(ERROR,
4967  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4968  errmsg("record \"%s\" is not assigned yet",
4969  rec->refname),
4970  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
4971  /* Make sure we have a valid type/typmod setting */
4972  BlessTupleDesc(rec->tupdesc);
4973  typeid = rec->tupdesc->tdtypeid;
4974  break;
4975  }
4976 
4978  {
4979  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
4980  PLpgSQL_rec *rec;
4981  int fno;
4982 
4983  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
4984  if (rec->tupdesc == NULL)
4985  ereport(ERROR,
4986  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4987  errmsg("record \"%s\" is not assigned yet",
4988  rec->refname),
4989  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
4990  fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
4991  if (fno == SPI_ERROR_NOATTRIBUTE)
4992  ereport(ERROR,
4993  (errcode(ERRCODE_UNDEFINED_COLUMN),
4994  errmsg("record \"%s\" has no field \"%s\"",
4995  rec->refname, recfield->fieldname)));
4996  typeid = SPI_gettypeid(rec->tupdesc, fno);
4997  break;
4998  }
4999 
5000  default:
5001  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5002  typeid = InvalidOid; /* keep compiler quiet */
5003  break;
5004  }
5005 
5006  return typeid;
5007 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:760
TupleDesc tupdesc
Definition: plpgsql.h:308
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:891
Oid tdtypeid
Definition: tupdesc.h:77
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:907
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
#define SPI_ERROR_NOATTRIBUTE
Definition: spi.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
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 5016 of file pl_exec.c.

References tupleDesc::attrs, 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, NULL, 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 make_datum_param().

5019 {
5020  switch (datum->dtype)
5021  {
5022  case PLPGSQL_DTYPE_VAR:
5023  {
5024  PLpgSQL_var *var = (PLpgSQL_var *) datum;
5025 
5026  *typeid = var->datatype->typoid;
5027  *typmod = var->datatype->atttypmod;
5028  *collation = var->datatype->collation;
5029  break;
5030  }
5031 
5032  case PLPGSQL_DTYPE_ROW:
5033  {
5034  PLpgSQL_row *row = (PLpgSQL_row *) datum;
5035 
5036  if (!row->rowtupdesc) /* should not happen */
5037  elog(ERROR, "row variable has no tupdesc");
5038  /* Make sure we have a valid type/typmod setting */
5039  BlessTupleDesc(row->rowtupdesc);
5040  *typeid = row->rowtupdesc->tdtypeid;
5041  /* do NOT return the mutable typmod of a RECORD variable */
5042  *typmod = -1;
5043  /* composite types are never collatable */
5044  *collation = InvalidOid;
5045  break;
5046  }
5047 
5048  case PLPGSQL_DTYPE_REC:
5049  {
5050  PLpgSQL_rec *rec = (PLpgSQL_rec *) datum;
5051 
5052  if (rec->tupdesc == NULL)
5053  ereport(ERROR,
5054  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
5055  errmsg("record \"%s\" is not assigned yet",
5056  rec->refname),
5057  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
5058  /* Make sure we have a valid type/typmod setting */
5059  BlessTupleDesc(rec->tupdesc);
5060  *typeid = rec->tupdesc->tdtypeid;
5061  /* do NOT return the mutable typmod of a RECORD variable */
5062  *typmod = -1;
5063  /* composite types are never collatable */
5064  *collation = InvalidOid;
5065  break;
5066  }
5067 
5069  {
5070  PLpgSQL_recfield *recfield = (PLpgSQL_recfield *) datum;
5071  PLpgSQL_rec *rec;
5072  int fno;
5073 
5074  rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
5075  if (rec->tupdesc == NULL)
5076  ereport(ERROR,
5077  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
5078  errmsg("record \"%s\" is not assigned yet",
5079  rec->refname),
5080  errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
5081  fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
5082  if (fno == SPI_ERROR_NOATTRIBUTE)
5083  ereport(ERROR,
5084  (errcode(ERRCODE_UNDEFINED_COLUMN),
5085  errmsg("record \"%s\" has no field \"%s\"",
5086  rec->refname, recfield->fieldname)));
5087  *typeid = SPI_gettypeid(rec->tupdesc, fno);
5088  if (fno > 0)
5089  *typmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
5090  else
5091  *typmod = -1;
5092  if (fno > 0)
5093  *collation = rec->tupdesc->attrs[fno - 1]->attcollation;
5094  else /* no system column types have collation */
5095  *collation = InvalidOid;
5096  break;
5097  }
5098 
5099  default:
5100  elog(ERROR, "unrecognized dtype: %d", datum->dtype);
5101  *typeid = InvalidOid; /* keep compiler quiet */
5102  *typmod = -1;
5103  *collation = InvalidOid;
5104  break;
5105  }
5106 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:760
TupleDesc tupdesc
Definition: plpgsql.h:308
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:891
Oid tdtypeid
Definition: tupdesc.h:77
PLpgSQL_type * datatype
Definition: plpgsql.h:261
Form_pg_attribute * attrs
Definition: tupdesc.h:74
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:907
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
#define SPI_ERROR_NOATTRIBUTE
Definition: spi.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define ereport(elevel, rest)
Definition: elog.h:122
Oid collation
Definition: plpgsql.h:185
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
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 616 of file pl_exec.c.

References PLpgSQL_function::action, ErrorContextCallback::arg, 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, NULL, 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(), 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().

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

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

Referenced by _PG_init().

2564 {
2565  HASHCTL ctl;
2566 
2567  /* don't allow double-initialization */
2569 
2570  memset(&ctl, 0, sizeof(ctl));
2571  ctl.keysize = sizeof(PLpgSQL_func_hashkey);
2572  ctl.entrysize = sizeof(plpgsql_HashEnt);
2573  plpgsql_HashTable = hash_create("PLpgSQL function cache",
2575  &ctl,
2576  HASH_ELEM | HASH_BLOBS);
2577 }
#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:301
Size keysize
Definition: hsearch.h:72
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
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(), NULL, 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
#define NULL
Definition: c.h:229
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, NULL, 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:357
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:849
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:358
#define offsetof(type, field)
Definition: c.h:555
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, NULL, 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:357
#define NULL
Definition: c.h:229
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
void plpgsql_ns_init ( void  )

Definition at line 45 of file pl_funcs.c.

References NULL.

Referenced by do_compile(), and plpgsql_compile_inline().

46 {
47  ns_top = NULL;
48 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
#define NULL
Definition: c.h:229
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, NULL, 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:357
#define NULL
Definition: c.h:229
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:358
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, NULL, 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:357
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:358
void plpgsql_ns_pop ( void  )

Definition at line 69 of file pl_funcs.c.

References Assert, PLpgSQL_nsitem::itemtype, NULL, 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:357
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
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 NULL, 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:81
#define NULL
Definition: c.h:229
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 1829 of file pl_comp.c.

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

1830 {
1831  Oid classOid;
1832  RangeVar *relvar;
1833  MemoryContext oldCxt;
1834 
1835  if (list_length(idents) != 2)
1836  return NULL;
1837 
1838  /* Avoid memory leaks in long-term function context */
1840 
1841  /* Look up relation name. Can't lock it - we might not have privileges. */
1842  relvar = makeRangeVar(strVal(linitial(idents)),
1843  strVal(lsecond(idents)),
1844  -1);
1845  classOid = RangeVarGetRelid(relvar, NoLock, false);
1846 
1847  MemoryContextSwitchTo(oldCxt);
1848 
1849  /* Build and return the row type struct */
1850  return plpgsql_build_datatype(get_rel_type_id(classOid), -1, InvalidOid);
1851 }
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2125
#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:114
#define linitial(l)
Definition: pg_list.h:110
#define NoLock
Definition: lockdefs.h:34
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1745
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
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 1691 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, NULL, ObjectIdGetDatum, OidIsValid, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_VAR, RangeVarGetRelid, ReleaseSysCache(), RELKIND_COMPOSITE_TYPE, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RelnameGetRelid(), RELOID, SearchSysCache1, SearchSysCacheAttName(), strVal, and TYPEOID.

1692 {
1693  PLpgSQL_type *dtype = NULL;
1694  PLpgSQL_nsitem *nse;
1695  const char *fldname;
1696  Oid classOid;
1697  HeapTuple classtup = NULL;
1698  HeapTuple attrtup = NULL;
1699  HeapTuple typetup = NULL;
1700  Form_pg_class classStruct;
1701  Form_pg_attribute attrStruct;
1702  MemoryContext oldCxt;
1703 
1704  /* Avoid memory leaks in the long-term function context */
1706 
1707  if (list_length(idents) == 2)
1708  {
1709  /*
1710  * Do a lookup in the current namespace stack. We don't need to check
1711  * number of names matched, because we will only consider scalar
1712  * variables.
1713  */
1714  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1715  strVal(linitial(idents)),
1716  strVal(lsecond(idents)),
1717  NULL,
1718  NULL);
1719 
1720  if (nse != NULL && nse->itemtype == PLPGSQL_NSTYPE_VAR)
1721  {
1722  dtype = ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1723  goto done;
1724  }
1725 
1726  /*
1727  * First word could also be a table name
1728  */
1729  classOid = RelnameGetRelid(strVal(linitial(idents)));
1730  if (!OidIsValid(classOid))
1731  goto done;
1732  fldname = strVal(lsecond(idents));
1733  }
1734  else if (list_length(idents) == 3)
1735  {
1736  RangeVar *relvar;
1737 
1738  relvar = makeRangeVar(strVal(linitial(idents)),
1739  strVal(lsecond(idents)),
1740  -1);
1741  /* Can't lock relation - we might not have privileges. */
1742  classOid = RangeVarGetRelid(relvar, NoLock, true);
1743  if (!OidIsValid(classOid))
1744  goto done;
1745  fldname = strVal(lthird(idents));
1746  }
1747  else
1748  goto done;
1749 
1750  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classOid));
1751  if (!HeapTupleIsValid(classtup))
1752  goto done;
1753  classStruct = (Form_pg_class) GETSTRUCT(classtup);
1754 
1755  /*
1756  * It must be a relation, sequence, view, materialized view, composite
1757  * type, or foreign table
1758  */
1759  if (classStruct->relkind != RELKIND_RELATION &&
1760  classStruct->relkind != RELKIND_SEQUENCE &&
1761  classStruct->relkind != RELKIND_VIEW &&
1762  classStruct->relkind != RELKIND_MATVIEW &&
1763  classStruct->relkind != RELKIND_COMPOSITE_TYPE &&
1764  classStruct->relkind != RELKIND_FOREIGN_TABLE)
1765  goto done;
1766 
1767  /*
1768  * Fetch the named table field and its type
1769  */
1770  attrtup = SearchSysCacheAttName(classOid, fldname);
1771  if (!HeapTupleIsValid(attrtup))
1772  goto done;
1773  attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup);
1774 
1775  typetup = SearchSysCache1(TYPEOID,
1776  ObjectIdGetDatum(attrStruct->atttypid));
1777  if (!HeapTupleIsValid(typetup))
1778  elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid);
1779 
1780  /*
1781  * Found that - build a compiler type struct in the caller's cxt and
1782  * return it
1783  */
1784  MemoryContextSwitchTo(oldCxt);
1785  dtype = build_datatype(typetup,
1786  attrStruct->atttypmod,
1787  attrStruct->attcollation);
1789 
1790 done:
1791  if (HeapTupleIsValid(classtup))
1792  ReleaseSysCache(classtup);
1793  if (HeapTupleIsValid(attrtup))
1794  ReleaseSysCache(attrtup);
1795  if (HeapTupleIsValid(typetup))
1796  ReleaseSysCache(typetup);
1797 
1798  MemoryContextSwitchTo(oldCxt);
1799  return dtype;
1800 }
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:653
#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:538
#define lsecond(l)
Definition: pg_list.h:114
#define RELKIND_COMPOSITE_TYPE
Definition: pg_class.h:166
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define linitial(l)
Definition: pg_list.h:110
#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:184
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
static int list_length(const List *l)
Definition: pg_list.h:89
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1204
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:2145
#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:118
#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 1411 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, NULL, 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().

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

Definition at line 2260 of file pl_comp.c.

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

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

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

Definition at line 1355 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, NULL, 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().

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

Definition at line 1808 of file pl_comp.c.

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

1809 {
1810  Oid classOid;
1811 
1812  /* Lookup the relation */
1813  classOid = RelnameGetRelid(ident);
1814  if (!OidIsValid(classOid))
1815  ereport(ERROR,
1817  errmsg("relation \"%s\" does not exist", ident)));
1818 
1819  /* Build and return the row type struct */
1820  return plpgsql_build_datatype(get_rel_type_id(classOid), -1, InvalidOid);
1821 }
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation)
Definition: pl_comp.c:2125
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:61
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:653
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1745
#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 1628 of file pl_comp.c.

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

1629 {
1630  PLpgSQL_type *dtype;
1631  PLpgSQL_nsitem *nse;
1632  HeapTuple typeTup;
1633 
1634  /*
1635  * Do a lookup in the current namespace stack
1636  */
1637  nse = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1638  ident, NULL, NULL,
1639  NULL);
1640 
1641  if (nse != NULL)
1642  {
1643  switch (nse->itemtype)
1644  {
1645  case PLPGSQL_NSTYPE_VAR:
1646  return ((PLpgSQL_var *) (plpgsql_Datums[nse->itemno]))->datatype;
1647 
1648  /* XXX perhaps allow REC/ROW here? */
1649 
1650  default:
1651  return NULL;
1652  }
1653  }
1654 
1655  /*
1656  * Word wasn't found in the namespace stack. Try to find a data type with
1657  * that name, but ignore shell types and complex types.
1658  */
1659  typeTup = LookupTypeName(NULL, makeTypeName(ident), NULL, false);
1660  if (typeTup)
1661  {
1662  Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
1663 
1664  if (!typeStruct->typisdefined ||
1665  typeStruct->typrelid != InvalidOid)
1666  {
1667  ReleaseSysCache(typeTup);
1668  return NULL;
1669  }
1670 
1671  dtype = build_datatype(typeTup, -1,
1673 
1674  ReleaseSysCache(typeTup);
1675  return dtype;
1676  }
1677 
1678  /*
1679  * Nothing found - up to now it's a word without any special meaning for
1680  * us.
1681  */
1682  return NULL;
1683 }
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:824
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define InvalidOid
Definition: postgres_ext.h:36
TypeName * makeTypeName(char *typnam)
Definition: makefuncs.c:441
#define NULL
Definition: c.h:229
static PLpgSQL_type * build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
Definition: pl_comp.c:2145
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 1018 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().

1019 {
1023  /* no need to use p_coerce_param_hook */
1024  pstate->p_ref_hook_state = (void *) expr;
1025 }
static Node * plpgsql_pre_column_ref(ParseState *pstate, ColumnRef *cref)
Definition: pl_comp.c:1031
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:203
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:204
static Node * plpgsql_param_ref(ParseState *pstate, ParamRef *pref)
Definition: pl_comp.c:1089
void * p_ref_hook_state
Definition: parse_node.h:206
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:202
static Node * plpgsql_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var)
Definition: pl_comp.c:1045
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 2224 of file pl_comp.c.

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

Referenced by exec_stmt_raise().

2225 {
2226  int i;
2227 
2228  if (allow_sqlstate)
2229  {
2230  if (strlen(condname) == 5 &&
2231  strspn(condname, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
2232  return MAKE_SQLSTATE(condname[0],
2233  condname[1],
2234  condname[2],
2235  condname[3],
2236  condname[4]);
2237  }
2238 
2239  for (i = 0; exception_label_map[i].label != NULL; i++)
2240  {
2241  if (strcmp(condname, exception_label_map[i].label) == 0)
2243  }
2244 
2245  ereport(ERROR,
2246  (errcode(ERRCODE_UNDEFINED_OBJECT),
2247  errmsg("unrecognized exception condition \"%s\"",
2248  condname)));
2249  return 0; /* keep compiler quiet */
2250 }
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:81
#define NULL
Definition: c.h:229
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(), NULL, 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
#define NULL
Definition: c.h:229
int internalerrposition(int cursorpos)
Definition: elog.c:1141
void plpgsql_scanner_finish ( void  )

Definition at line 729 of file pl_scanner.c.

References NULL, 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
#define NULL
Definition: c.h:229
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:366
#define _(x)
Definition: elog.c:84
void plpgsql_subxact_cb ( SubXactEvent  event,
SubTransactionId  mySubid,
SubTransactionId  parentSubid,
void *  arg 
)

Definition at line 7114 of file pl_exec.c.

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

Referenced by _PG_init(), and plpgsql_inline_handler().

7116 {
7117  if (event == SUBXACT_EVENT_COMMIT_SUB || event == SUBXACT_EVENT_ABORT_SUB)
7118  {
7119  while (simple_econtext_stack != NULL &&
7120  simple_econtext_stack->xact_subxid == mySubid)
7121  {
7123 
7125  (event == SUBXACT_EVENT_COMMIT_SUB));
7126  next = simple_econtext_stack->next;
7129  }
7130  }
7131 }
static int32 next
Definition: blutils.c:210
struct SimpleEcontextStackEntry * next
Definition: pl_exec.c:85
void pfree(void *pointer)
Definition: mcxt.c:950
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:344
#define NULL
Definition: c.h:229
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 @114 value
static const ScanKeyword unreserved_keywords[]
Definition: pl_scanner.c:99
int i
void plpgsql_xact_cb ( XactEvent  event,
void *  arg 
)

Definition at line 7082 of file pl_exec.c.

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

Referenced by _PG_init().

7083 {
7084  /*
7085  * If we are doing a clean transaction shutdown, free the EState (so that
7086  * any remaining resources will be released correctly). In an abort, we
7087  * expect the regular abort recovery procedures to release everything of
7088  * interest.
7089  */
7090  if (event == XACT_EVENT_COMMIT || event == XACT_EVENT_PREPARE)
7091  {
7092  /* Shouldn't be any econtext stack entries left at commit */
7094 
7098  }
7099  else if (event == XACT_EVENT_ABORT)
7100  {
7103  }
7104 }
void FreeExecutorState(EState *estate)
Definition: execUtils.c:173
static SimpleEcontextStackEntry * simple_econtext_stack
Definition: pl_exec.c:89
static EState * shared_simple_eval_estate
Definition: pl_exec.c:88
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
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