1997-11-25 23:07:18 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* parse_node.h
|
2003-04-30 00:13:11 +02:00
|
|
|
* Internal definitions for parser
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/parser/parse_node.h
|
1997-11-25 23:07:18 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PARSE_NODE_H
|
|
|
|
#define PARSE_NODE_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "utils/relcache.h"
|
1997-11-25 23:07:18 +01:00
|
|
|
|
2009-10-31 02:41:31 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function signatures for parser hooks
|
|
|
|
*/
|
|
|
|
typedef struct ParseState ParseState;
|
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
typedef Node *(*PreParseColumnRefHook) (ParseState *pstate, ColumnRef *cref);
|
|
|
|
typedef Node *(*PostParseColumnRefHook) (ParseState *pstate, ColumnRef *cref, Node *var);
|
|
|
|
typedef Node *(*ParseParamRefHook) (ParseState *pstate, ParamRef *pref);
|
|
|
|
typedef Node *(*CoerceParamHook) (ParseState *pstate, Param *param,
|
|
|
|
Oid targetTypeId, int32 targetTypeMod,
|
|
|
|
int location);
|
2009-10-31 02:41:31 +01:00
|
|
|
|
|
|
|
|
2000-09-12 23:07:18 +02:00
|
|
|
/*
|
|
|
|
* State information used during parse analysis
|
2001-02-14 22:35:07 +01:00
|
|
|
*
|
2006-03-14 23:48:25 +01:00
|
|
|
* parentParseState: NULL in a top-level ParseState. When parsing a subquery,
|
|
|
|
* links to current parse state of outer query.
|
|
|
|
*
|
|
|
|
* p_sourcetext: source string that generated the raw parsetree being
|
2006-10-04 02:30:14 +02:00
|
|
|
* analyzed, or NULL if not available. (The string is used only to
|
2006-03-14 23:48:25 +01:00
|
|
|
* generate cursor positions in error messages: we need it to convert
|
|
|
|
* byte-wise locations in parse structures to character-wise cursor
|
|
|
|
* positions.)
|
|
|
|
*
|
2001-02-14 22:35:07 +01:00
|
|
|
* p_rtable: list of RTEs that will become the rangetable of the query.
|
|
|
|
* Note that neither relname nor refname of these entries are necessarily
|
|
|
|
* unique; searching the rtable by name is a bad idea.
|
|
|
|
*
|
2009-01-22 21:16:10 +01:00
|
|
|
* p_joinexprs: list of JoinExpr nodes associated with p_rtable entries.
|
|
|
|
* This is one-for-one with p_rtable, but contains NULLs for non-join
|
|
|
|
* RTEs, and may be shorter than p_rtable if the last RTE(s) aren't joins.
|
|
|
|
*
|
2001-02-14 22:35:07 +01:00
|
|
|
* p_joinlist: list of join items (RangeTblRef and JoinExpr nodes) that
|
|
|
|
* will become the fromlist of the query's top-level FromExpr node.
|
|
|
|
*
|
2005-06-05 02:38:11 +02:00
|
|
|
* p_relnamespace: list of RTEs that represents the current namespace for
|
|
|
|
* table lookup, ie, those RTEs that are accessible by qualified names.
|
|
|
|
* This may be just a subset of the rtable + joinlist, and/or may contain
|
|
|
|
* entries that are not yet added to the main joinlist.
|
|
|
|
*
|
|
|
|
* p_varnamespace: list of RTEs that represents the current namespace for
|
|
|
|
* column lookup, ie, those RTEs that are accessible by unqualified names.
|
|
|
|
* This is different from p_relnamespace because a JOIN without an alias does
|
|
|
|
* not hide the contained tables (so they must still be in p_relnamespace)
|
|
|
|
* but it does hide their columns (unqualified references to the columns must
|
2009-10-21 22:22:38 +02:00
|
|
|
* refer to the JOIN, not the member tables). Other special RTEs such as
|
|
|
|
* NEW/OLD for rules may also appear in just one of these lists.
|
2003-04-30 00:13:11 +02:00
|
|
|
*
|
2008-10-04 23:56:55 +02:00
|
|
|
* p_ctenamespace: list of CommonTableExprs (WITH items) that are visible
|
|
|
|
* at the moment. This is different from p_relnamespace because you have
|
|
|
|
* to make an RTE before you can access a CTE.
|
|
|
|
*
|
2008-10-08 03:14:44 +02:00
|
|
|
* p_future_ctes: list of CommonTableExprs (WITH items) that are not yet
|
2009-06-11 16:49:15 +02:00
|
|
|
* visible due to scope rules. This is used to help improve error messages.
|
2008-10-08 03:14:44 +02:00
|
|
|
*
|
2009-09-09 05:32:52 +02:00
|
|
|
* p_parent_cte: CommonTableExpr that immediately contains the current query,
|
|
|
|
* if any.
|
|
|
|
*
|
2008-12-28 19:54:01 +01:00
|
|
|
* p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses.
|
|
|
|
* We collect these while transforming expressions and then transform them
|
|
|
|
* afterwards (so that any resjunk tlist items needed for the sort/group
|
|
|
|
* clauses end up at the end of the query tlist). A WindowDef's location in
|
|
|
|
* this list, counting from 1, is the winref number to use to reference it.
|
2000-02-15 04:38:29 +01:00
|
|
|
*/
|
2009-10-31 02:41:31 +01:00
|
|
|
struct ParseState
|
1997-11-25 23:07:18 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
struct ParseState *parentParseState; /* stack link */
|
2006-03-14 23:48:25 +01:00
|
|
|
const char *p_sourcetext; /* source text, or NULL if not available */
|
2000-09-12 23:07:18 +02:00
|
|
|
List *p_rtable; /* range table so far */
|
2009-01-22 21:16:10 +01:00
|
|
|
List *p_joinexprs; /* JoinExprs for RTE_JOIN p_rtable entries */
|
2001-03-22 05:01:46 +01:00
|
|
|
List *p_joinlist; /* join items so far (will become FromExpr
|
|
|
|
* node's fromlist) */
|
2005-10-15 04:49:52 +02:00
|
|
|
List *p_relnamespace; /* current namespace for relations */
|
|
|
|
List *p_varnamespace; /* current namespace for columns */
|
2008-10-04 23:56:55 +02:00
|
|
|
List *p_ctenamespace; /* current namespace for common table exprs */
|
2008-10-08 03:14:44 +02:00
|
|
|
List *p_future_ctes; /* common table exprs not yet in namespace */
|
2009-09-09 05:32:52 +02:00
|
|
|
CommonTableExpr *p_parent_cte; /* this query's containing CTE */
|
2008-12-28 19:54:01 +01:00
|
|
|
List *p_windowdefs; /* raw representations of window clauses */
|
2003-04-30 00:13:11 +02:00
|
|
|
int p_next_resno; /* next targetlist resno to assign */
|
2006-10-04 02:30:14 +02:00
|
|
|
List *p_locking_clause; /* raw FOR UPDATE/FOR SHARE info */
|
|
|
|
Node *p_value_substitute; /* what to replace VALUE with, if any */
|
1998-01-15 20:00:16 +01:00
|
|
|
bool p_hasAggs;
|
2008-12-28 19:54:01 +01:00
|
|
|
bool p_hasWindowFuncs;
|
1998-01-17 05:53:46 +01:00
|
|
|
bool p_hasSubLinks;
|
1998-01-15 20:00:16 +01:00
|
|
|
bool p_is_insert;
|
1997-11-25 23:07:18 +01:00
|
|
|
bool p_is_update;
|
2009-10-27 18:11:18 +01:00
|
|
|
bool p_locked_from_parent;
|
1997-11-25 23:07:18 +01:00
|
|
|
Relation p_target_relation;
|
|
|
|
RangeTblEntry *p_target_rangetblentry;
|
2009-10-31 02:41:31 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optional hook functions for parser callbacks. These are null unless
|
|
|
|
* set up by the caller of make_parsestate.
|
|
|
|
*/
|
|
|
|
PreParseColumnRefHook p_pre_columnref_hook;
|
|
|
|
PostParseColumnRefHook p_post_columnref_hook;
|
|
|
|
ParseParamRefHook p_paramref_hook;
|
|
|
|
CoerceParamHook p_coerce_param_hook;
|
2010-02-26 03:01:40 +01:00
|
|
|
void *p_ref_hook_state; /* common passthrough link for above */
|
2009-10-31 02:41:31 +01:00
|
|
|
};
|
1997-11-25 23:07:18 +01:00
|
|
|
|
2008-09-01 22:42:46 +02:00
|
|
|
/* Support for parser_errposition_callback function */
|
|
|
|
typedef struct ParseCallbackState
|
|
|
|
{
|
|
|
|
ParseState *pstate;
|
|
|
|
int location;
|
|
|
|
ErrorContextCallback errcontext;
|
|
|
|
} ParseCallbackState;
|
|
|
|
|
|
|
|
|
1998-01-19 06:06:41 +01:00
|
|
|
extern ParseState *make_parsestate(ParseState *parentParseState);
|
2007-06-24 00:12:52 +02:00
|
|
|
extern void free_parsestate(ParseState *pstate);
|
2006-03-14 23:48:25 +01:00
|
|
|
extern int parser_errposition(ParseState *pstate, int location);
|
|
|
|
|
2008-09-01 22:42:46 +02:00
|
|
|
extern void setup_parser_errposition_callback(ParseCallbackState *pcbstate,
|
|
|
|
ParseState *pstate, int location);
|
|
|
|
extern void cancel_parser_errposition_callback(ParseCallbackState *pcbstate);
|
|
|
|
|
2008-08-29 01:09:48 +02:00
|
|
|
extern Var *make_var(ParseState *pstate, RangeTblEntry *rte, int attrno,
|
2009-06-11 16:49:15 +02:00
|
|
|
int location);
|
2004-08-29 07:07:03 +02:00
|
|
|
extern Oid transformArrayType(Oid arrayType);
|
1999-07-19 02:26:20 +02:00
|
|
|
extern ArrayRef *transformArraySubscripts(ParseState *pstate,
|
2000-04-12 19:17:23 +02:00
|
|
|
Node *arrayBase,
|
2001-02-14 22:35:07 +01:00
|
|
|
Oid arrayType,
|
2004-06-09 21:08:20 +02:00
|
|
|
Oid elementType,
|
|
|
|
int32 elementTypMod,
|
2000-04-12 19:17:23 +02:00
|
|
|
List *indirection,
|
|
|
|
Node *assignFrom);
|
2008-09-01 22:42:46 +02:00
|
|
|
extern Const *make_const(ParseState *pstate, Value *value, int location);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PARSE_NODE_H */
|