aboutsummaryrefslogtreecommitdiff
path: root/src/include/nodes/params.h
blob: 58e2fe691fa7c2a7d6e0af55d24ef71f680787ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*-------------------------------------------------------------------------
 *
 * params.h
 *	  Declarations of stuff needed to handle parameterized plans.
 *
 *
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $PostgreSQL: pgsql/src/include/nodes/params.h,v 1.28 2004/12/31 22:03:34 pgsql Exp $
 *
 *-------------------------------------------------------------------------
 */
#ifndef PARAMS_H
#define PARAMS_H

#include "access/attnum.h"


/* ----------------
 * The following are the possible values for the 'paramkind'
 * field of a Param node.
 *
 * PARAM_NAMED: The parameter has a name, i.e. something
 *				like `$.salary' or `$.foobar'.
 *				In this case field `paramname' must be a valid name.
 *
 * PARAM_NUM:	The parameter has only a numeric identifier,
 *				i.e. something like `$1', `$2' etc.
 *				The number is contained in the `paramid' field.
 *
 * PARAM_EXEC:	The parameter is an internal executor parameter.
 *				It has a number contained in the `paramid' field.
 *
 * PARAM_INVALID should never appear in a Param node; it's used to mark
 * the end of a ParamListInfo array.
 *
 * NOTE: As of PostgreSQL 7.3, named parameters aren't actually used and
 * so the code that handles PARAM_NAMED cases is dead code.  We leave it
 * in place since it might be resurrected someday.
 * ----------------
 */

#define PARAM_NAMED		11
#define PARAM_NUM		12
#define PARAM_EXEC		15
#define PARAM_INVALID	100


/* ----------------
 *	  ParamListInfo
 *
 *	  ParamListInfo entries are used to pass parameters into the executor
 *	  for parameterized plans.	Each entry in the array defines the value
 *	  to be substituted for a PARAM_NAMED or PARAM_NUM parameter.
 *
 *		kind   : the kind of parameter (PARAM_NAMED or PARAM_NUM)
 *		name   : the parameter name (valid if kind == PARAM_NAMED)
 *		id	   : the parameter id (valid if kind == PARAM_NUM)
 *		ptype  : the type of the parameter value
 *		isnull : true if the value is null (if so 'value' is undefined)
 *		value  : the value that has to be substituted in the place
 *				 of the parameter.
 *
 *	 ParamListInfo is to be used as an array of ParamListInfoData
 *	 records.  A dummy record with kind == PARAM_INVALID marks the end
 *	 of the array.
 * ----------------
 */

typedef struct ParamListInfoData
{
	int			kind;
	char	   *name;
	AttrNumber	id;
	Oid			ptype;
	bool		isnull;
	Datum		value;
} ParamListInfoData;

typedef ParamListInfoData *ParamListInfo;


/* ----------------
 *	  ParamExecData
 *
 *	  ParamExecData entries are used for executor internal parameters
 *	  (that is, values being passed into or out of a sub-query).  The
 *	  paramid of a PARAM_EXEC Param is a (zero-based) index into an
 *	  array of ParamExecData records, which is referenced through
 *	  es_param_exec_vals or ecxt_param_exec_vals.
 *
 *	  If execPlan is not NULL, it points to a SubPlanState node that needs
 *	  to be executed to produce the value.	(This is done so that we can have
 *	  lazy evaluation of InitPlans: they aren't executed until/unless a
 *	  result value is needed.)	Otherwise the value is assumed to be valid
 *	  when needed.
 * ----------------
 */

typedef struct ParamExecData
{
	void	   *execPlan;		/* should be "SubPlanState *" */
	Datum		value;
	bool		isnull;
} ParamExecData;


/* Functions found in src/backend/nodes/params.c */
extern ParamListInfo copyParamList(ParamListInfo from);
extern ParamListInfo lookupParam(ParamListInfo paramList, int thisParamKind,
			const char *thisParamName, AttrNumber thisParamId,
			bool noError);

#endif   /* PARAMS_H */