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
|
|
|
*
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, 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
|
|
|
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
/*
|
|
|
|
* Expression kinds distinguished by transformExpr(). Many of these are not
|
|
|
|
* semantically distinct so far as expression transformation goes; rather,
|
|
|
|
* we distinguish them so that context-specific error messages can be printed.
|
|
|
|
*
|
|
|
|
* Note: EXPR_KIND_OTHER is not used in the core code, but is left for use
|
|
|
|
* by extension code that might need to call transformExpr(). The core code
|
|
|
|
* will not enforce any context-driven restrictions on EXPR_KIND_OTHER
|
|
|
|
* expressions, so the caller would have to check for sub-selects, aggregates,
|
2016-09-13 19:54:24 +02:00
|
|
|
* window functions, SRFs, etc if those need to be disallowed.
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
*/
|
|
|
|
typedef enum ParseExprKind
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
EXPR_KIND_NONE = 0, /* "not in an expression" */
|
|
|
|
EXPR_KIND_OTHER, /* reserved for extensions */
|
|
|
|
EXPR_KIND_JOIN_ON, /* JOIN ON */
|
|
|
|
EXPR_KIND_JOIN_USING, /* JOIN USING */
|
|
|
|
EXPR_KIND_FROM_SUBSELECT, /* sub-SELECT in FROM clause */
|
|
|
|
EXPR_KIND_FROM_FUNCTION, /* function in FROM clause */
|
|
|
|
EXPR_KIND_WHERE, /* WHERE */
|
|
|
|
EXPR_KIND_HAVING, /* HAVING */
|
2013-07-17 02:15:36 +02:00
|
|
|
EXPR_KIND_FILTER, /* FILTER */
|
2013-05-29 22:58:43 +02:00
|
|
|
EXPR_KIND_WINDOW_PARTITION, /* window definition PARTITION BY */
|
|
|
|
EXPR_KIND_WINDOW_ORDER, /* window definition ORDER BY */
|
|
|
|
EXPR_KIND_WINDOW_FRAME_RANGE, /* window frame clause with RANGE */
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
EXPR_KIND_WINDOW_FRAME_ROWS, /* window frame clause with ROWS */
|
2013-05-29 22:58:43 +02:00
|
|
|
EXPR_KIND_SELECT_TARGET, /* SELECT target list item */
|
|
|
|
EXPR_KIND_INSERT_TARGET, /* INSERT target list item */
|
|
|
|
EXPR_KIND_UPDATE_SOURCE, /* UPDATE assignment source item */
|
|
|
|
EXPR_KIND_UPDATE_TARGET, /* UPDATE assignment target item */
|
|
|
|
EXPR_KIND_GROUP_BY, /* GROUP BY */
|
|
|
|
EXPR_KIND_ORDER_BY, /* ORDER BY */
|
|
|
|
EXPR_KIND_DISTINCT_ON, /* DISTINCT ON */
|
|
|
|
EXPR_KIND_LIMIT, /* LIMIT */
|
|
|
|
EXPR_KIND_OFFSET, /* OFFSET */
|
|
|
|
EXPR_KIND_RETURNING, /* RETURNING */
|
|
|
|
EXPR_KIND_VALUES, /* VALUES */
|
|
|
|
EXPR_KIND_CHECK_CONSTRAINT, /* CHECK constraint for a table */
|
|
|
|
EXPR_KIND_DOMAIN_CHECK, /* CHECK constraint for a domain */
|
|
|
|
EXPR_KIND_COLUMN_DEFAULT, /* default value for a table column */
|
|
|
|
EXPR_KIND_FUNCTION_DEFAULT, /* default parameter value for function */
|
|
|
|
EXPR_KIND_INDEX_EXPRESSION, /* index expression */
|
|
|
|
EXPR_KIND_INDEX_PREDICATE, /* index predicate */
|
|
|
|
EXPR_KIND_ALTER_COL_TRANSFORM, /* transform expr in ALTER COLUMN TYPE */
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
EXPR_KIND_EXECUTE_PARAMETER, /* parameter value in EXECUTE */
|
2015-07-30 00:37:48 +02:00
|
|
|
EXPR_KIND_TRIGGER_WHEN, /* WHEN condition in CREATE TRIGGER */
|
Implement table partitioning.
Table partitioning is like table inheritance and reuses much of the
existing infrastructure, but there are some important differences.
The parent is called a partitioned table and is always empty; it may
not have indexes or non-inherited constraints, since those make no
sense for a relation with no data of its own. The children are called
partitions and contain all of the actual data. Each partition has an
implicit partitioning constraint. Multiple inheritance is not
allowed, and partitioning and inheritance can't be mixed. Partitions
can't have extra columns and may not allow nulls unless the parent
does. Tuples inserted into the parent are automatically routed to the
correct partition, so tuple-routing ON INSERT triggers are not needed.
Tuple routing isn't yet supported for partitions which are foreign
tables, and it doesn't handle updates that cross partition boundaries.
Currently, tables can be range-partitioned or list-partitioned. List
partitioning is limited to a single column, but range partitioning can
involve multiple columns. A partitioning "column" can be an
expression.
Because table partitioning is less general than table inheritance, it
is hoped that it will be easier to reason about properties of
partitions, and therefore that this will serve as a better foundation
for a variety of possible optimizations, including query planner
optimizations. The tuple routing based which this patch does based on
the implicit partitioning constraints is an example of this, but it
seems likely that many other useful optimizations are also possible.
Amit Langote, reviewed and tested by Robert Haas, Ashutosh Bapat,
Amit Kapila, Rajkumar Raghuwanshi, Corey Huinker, Jaime Casanova,
Rushabh Lathia, Erik Rijkers, among others. Minor revisions by me.
2016-12-07 19:17:43 +01:00
|
|
|
EXPR_KIND_POLICY, /* USING or WITH CHECK expr in policy */
|
|
|
|
EXPR_KIND_PARTITION_EXPRESSION /* PARTITION BY expression */
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
} ParseExprKind;
|
|
|
|
|
|
|
|
|
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
|
2014-05-06 18:12:18 +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.
|
|
|
|
*
|
2012-08-08 22:41:04 +02:00
|
|
|
* p_namespace: list of ParseNamespaceItems that represents the current
|
|
|
|
* namespace for table and column lookup. (The RTEs listed here may be just
|
|
|
|
* a subset of the whole rtable. See ParseNamespaceItem comments below.)
|
2012-08-08 01:02:54 +02:00
|
|
|
*
|
|
|
|
* p_lateral_active: TRUE if we are currently parsing a LATERAL subexpression
|
|
|
|
* of this parse level. This makes p_lateral_only namespace items visible,
|
|
|
|
* whereas they are not visible when p_lateral_active is FALSE.
|
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
|
2012-08-08 22:41:04 +02:00
|
|
|
* at the moment. This is entirely different from p_namespace because a CTE
|
|
|
|
* is not an RTE, rather "visibility" means you could make an RTE from it.
|
2008-10-04 23:56:55 +02:00
|
|
|
*
|
2008-10-08 03:14:44 +02:00
|
|
|
* p_future_ctes: list of CommonTableExprs (WITH items) that are not yet
|
2014-05-06 18:12:18 +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) */
|
2012-08-08 22:41:04 +02:00
|
|
|
List *p_namespace; /* currently-referenceable RTEs (List of
|
|
|
|
* ParseNamespaceItem) */
|
2012-08-08 01:02:54 +02:00
|
|
|
bool p_lateral_active; /* p_lateral_only items visible? */
|
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 */
|
Centralize the logic for detecting misplaced aggregates, window funcs, etc.
Formerly we relied on checking after-the-fact to see if an expression
contained aggregates, window functions, or sub-selects when it shouldn't.
This is grotty, easily forgotten (indeed, we had forgotten to teach
DefineIndex about rejecting window functions), and none too efficient
since it requires extra traversals of the parse tree. To improve matters,
define an enum type that classifies all SQL sub-expressions, store it in
ParseState to show what kind of expression we are currently parsing, and
make transformAggregateCall, transformWindowFuncCall, and transformSubLink
check the expression type and throw error if the type indicates the
construct is disallowed. This allows removal of a large number of ad-hoc
checks scattered around the code base. The enum type is sufficiently
fine-grained that we can still produce error messages of at least the
same specificity as before.
Bringing these error checks together revealed that we'd been none too
consistent about phrasing of the error messages, so standardize the wording
a bit.
Also, rewrite checking of aggregate arguments so that it requires only one
traversal of the arguments, rather than up to three as before.
In passing, clean up some more comments left over from add_missing_from
support, and annotate some tests that I think are dead code now that that's
gone. (I didn't risk actually removing said dead code, though.)
2012-08-10 17:35:33 +02:00
|
|
|
ParseExprKind p_expr_kind; /* what kind of expression we're parsing */
|
2003-04-30 00:13:11 +02:00
|
|
|
int p_next_resno; /* next targetlist resno to assign */
|
Implement UPDATE tab SET (col1,col2,...) = (SELECT ...), ...
This SQL-standard feature allows a sub-SELECT yielding multiple columns
(but only one row) to be used to compute the new values of several columns
to be updated. While the same results can be had with an independent
sub-SELECT per column, such a workaround can require a great deal of
duplicated computation.
The standard actually says that the source for a multi-column assignment
could be any row-valued expression. The implementation used here is
tightly tied to our existing sub-SELECT support and can't handle other
cases; the Bison grammar would have some issues with them too. However,
I don't feel too bad about this since other cases can be converted into
sub-SELECTs. For instance, "SET (a,b,c) = row_valued_function(x)" could
be written "SET (a,b,c) = (SELECT * FROM row_valued_function(x))".
2014-06-18 19:22:25 +02:00
|
|
|
List *p_multiassign_exprs; /* junk tlist entries for multiassign */
|
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;
|
2016-09-13 19:54:24 +02:00
|
|
|
bool p_hasTargetSRFs;
|
1998-01-17 05:53:46 +01:00
|
|
|
bool p_hasSubLinks;
|
2011-02-26 00:56:23 +01:00
|
|
|
bool p_hasModifyingCTE;
|
1998-01-15 20:00:16 +01:00
|
|
|
bool p_is_insert;
|
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
|
|
|
|
2012-08-08 22:41:04 +02:00
|
|
|
/*
|
|
|
|
* An element of a namespace list.
|
|
|
|
*
|
|
|
|
* Namespace items with p_rel_visible set define which RTEs are accessible by
|
|
|
|
* qualified names, while those with p_cols_visible set define which RTEs are
|
|
|
|
* accessible by unqualified names. These sets are different because a JOIN
|
|
|
|
* without an alias does not hide the contained tables (so they must be
|
|
|
|
* visible for qualified references) but it does hide their columns
|
|
|
|
* (unqualified references to the columns refer to the JOIN, not the member
|
|
|
|
* tables, so we must not complain that such a reference is ambiguous).
|
|
|
|
* Various special RTEs such as NEW/OLD for rules may also appear with only
|
|
|
|
* one flag set.
|
|
|
|
*
|
|
|
|
* While processing the FROM clause, namespace items may appear with
|
|
|
|
* p_lateral_only set, meaning they are visible only to LATERAL
|
2014-05-06 18:12:18 +02:00
|
|
|
* subexpressions. (The pstate's p_lateral_active flag tells whether we are
|
2013-05-29 22:58:43 +02:00
|
|
|
* inside such a subexpression at the moment.) If p_lateral_ok is not set,
|
2012-08-08 22:41:04 +02:00
|
|
|
* it's an error to actually use such a namespace item. One might think it
|
|
|
|
* would be better to just exclude such items from visibility, but the wording
|
2014-01-12 01:03:12 +01:00
|
|
|
* of SQL:2008 requires us to do it this way. We also use p_lateral_ok to
|
|
|
|
* forbid LATERAL references to an UPDATE/DELETE target table.
|
2012-08-08 22:41:04 +02:00
|
|
|
*
|
|
|
|
* At no time should a namespace list contain two entries that conflict
|
|
|
|
* according to the rules in checkNameSpaceConflicts; but note that those
|
|
|
|
* are more complicated than "must have different alias names", so in practice
|
|
|
|
* code searching a namespace list has to check for ambiguous references.
|
|
|
|
*/
|
2012-08-08 01:02:54 +02:00
|
|
|
typedef struct ParseNamespaceItem
|
|
|
|
{
|
|
|
|
RangeTblEntry *p_rte; /* The relation's rangetable entry */
|
2012-08-08 22:41:04 +02:00
|
|
|
bool p_rel_visible; /* Relation name is visible? */
|
2013-05-29 22:58:43 +02:00
|
|
|
bool p_cols_visible; /* Column names visible as unqualified refs? */
|
2012-08-08 01:02:54 +02:00
|
|
|
bool p_lateral_only; /* Is only visible to LATERAL expressions? */
|
|
|
|
bool p_lateral_ok; /* If so, does join type allow use? */
|
|
|
|
} ParseNamespaceItem;
|
|
|
|
|
2008-09-01 22:42:46 +02:00
|
|
|
/* Support for parser_errposition_callback function */
|
|
|
|
typedef struct ParseCallbackState
|
|
|
|
{
|
|
|
|
ParseState *pstate;
|
|
|
|
int location;
|
2012-11-12 14:10:24 +01:00
|
|
|
ErrorContextCallback errcallback;
|
2008-09-01 22:42:46 +02:00
|
|
|
} 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);
|
Improve handling of domains over arrays.
This patch eliminates various bizarre behaviors caused by sloppy thinking
about the difference between a domain type and its underlying array type.
In particular, the operation of updating one element of such an array
has to be considered as yielding a value of the underlying array type,
*not* a value of the domain, because there's no assurance that the
domain's CHECK constraints are still satisfied. If we're intending to
store the result back into a domain column, we have to re-cast to the
domain type so that constraints are re-checked.
For similar reasons, such a domain can't be blindly matched to an ANYARRAY
polymorphic parameter, because the polymorphic function is likely to apply
array-ish operations that could invalidate the domain constraints. For the
moment, we just forbid such matching. We might later wish to insert an
automatic downcast to the underlying array type, but such a change should
also change matching of domains to ANYELEMENT for consistency.
To ensure that all such logic is rechecked, this patch removes the original
hack of setting a domain's pg_type.typelem field to match its base type;
the typelem will always be zero instead. In those places where it's really
okay to look through the domain type with no other logic changes, use the
newly added get_base_element_type function in place of get_element_type.
catversion bumped due to change in pg_type contents.
Per bug #5717 from Richard Huxton and subsequent discussion.
2010-10-21 22:07:17 +02:00
|
|
|
extern Oid transformArrayType(Oid *arrayType, int32 *arrayTypmod);
|
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,
|
Improve handling of domains over arrays.
This patch eliminates various bizarre behaviors caused by sloppy thinking
about the difference between a domain type and its underlying array type.
In particular, the operation of updating one element of such an array
has to be considered as yielding a value of the underlying array type,
*not* a value of the domain, because there's no assurance that the
domain's CHECK constraints are still satisfied. If we're intending to
store the result back into a domain column, we have to re-cast to the
domain type so that constraints are re-checked.
For similar reasons, such a domain can't be blindly matched to an ANYARRAY
polymorphic parameter, because the polymorphic function is likely to apply
array-ish operations that could invalidate the domain constraints. For the
moment, we just forbid such matching. We might later wish to insert an
automatic downcast to the underlying array type, but such a change should
also change matching of domains to ANYELEMENT for consistency.
To ensure that all such logic is rechecked, this patch removes the original
hack of setting a domain's pg_type.typelem field to match its base type;
the typelem will always be zero instead. In those places where it's really
okay to look through the domain type with no other logic changes, use the
newly added get_base_element_type function in place of get_element_type.
catversion bumped due to change in pg_type contents.
Per bug #5717 from Richard Huxton and subsequent discussion.
2010-10-21 22:07:17 +02:00
|
|
|
int32 arrayTypMod,
|
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 */
|