1999-02-13 18:22:53 -05:00
|
|
|
/*-------------------------------------------------------------------------
|
1997-11-25 17:07:18 -05:00
|
|
|
*
|
1999-07-18 20:26:20 -04:00
|
|
|
* parse_relation.h
|
|
|
|
|
* prototypes for parse_relation.c.
|
1997-11-25 17:07:18 -05:00
|
|
|
*
|
|
|
|
|
*
|
2017-01-03 13:48:53 -05:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1997-11-25 17:07:18 -05:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/parser/parse_relation.h
|
1997-11-25 17:07:18 -05:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
1999-07-18 20:26:20 -04:00
|
|
|
#ifndef PARSE_RELATION_H
|
|
|
|
|
#define PARSE_RELATION_H
|
1997-11-25 17:07:18 -05:00
|
|
|
|
1999-07-15 19:04:24 -04:00
|
|
|
#include "parser/parse_node.h"
|
1997-11-25 17:07:18 -05:00
|
|
|
|
2015-03-11 10:44:04 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Support for fuzzily matching column.
|
|
|
|
|
*
|
|
|
|
|
* This is for building diagnostic messages, where non-exact matching
|
|
|
|
|
* attributes are suggested to the user. The struct's fields may be facets of
|
|
|
|
|
* a particular RTE, or of an entire range table, depending on context.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2015-05-23 21:35:49 -04:00
|
|
|
int distance; /* Weighted distance (lowest so far) */
|
|
|
|
|
RangeTblEntry *rfirst; /* RTE of first */
|
|
|
|
|
AttrNumber first; /* Closest attribute so far */
|
|
|
|
|
RangeTblEntry *rsecond; /* RTE of second */
|
|
|
|
|
AttrNumber second; /* Second closest attribute so far */
|
2015-03-11 10:44:04 -04:00
|
|
|
} FuzzyAttrMatchState;
|
|
|
|
|
|
|
|
|
|
|
2002-03-11 19:52:10 -05:00
|
|
|
extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate,
|
2002-09-04 16:31:48 -04:00
|
|
|
const char *schemaname,
|
|
|
|
|
const char *refname,
|
2008-09-01 16:42:46 -04:00
|
|
|
int location,
|
2002-09-04 16:31:48 -04:00
|
|
|
int *sublevels_up);
|
2008-10-05 22:12:56 -04:00
|
|
|
extern CommonTableExpr *scanNameSpaceForCTE(ParseState *pstate,
|
2009-06-11 10:49:15 -04:00
|
|
|
const char *refname,
|
|
|
|
|
Index *ctelevelsup);
|
2017-04-01 00:17:18 -04:00
|
|
|
extern bool scanNameSpaceForENR(ParseState *pstate, const char *refname);
|
2005-06-04 20:38:11 -04:00
|
|
|
extern void checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
|
|
|
|
|
List *namespace2);
|
2000-09-12 17:07:18 -04:00
|
|
|
extern int RTERangeTablePosn(ParseState *pstate,
|
2001-03-21 23:01:46 -05:00
|
|
|
RangeTblEntry *rte,
|
|
|
|
|
int *sublevels_up);
|
2004-04-02 14:07:02 -05:00
|
|
|
extern RangeTblEntry *GetRTEByRangeTablePosn(ParseState *pstate,
|
2004-08-29 01:07:03 -04:00
|
|
|
int varno,
|
|
|
|
|
int sublevels_up);
|
2008-10-06 11:15:22 -04:00
|
|
|
extern CommonTableExpr *GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte,
|
2009-06-11 10:49:15 -04:00
|
|
|
int rtelevelsup);
|
2004-04-02 14:07:02 -05:00
|
|
|
extern Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
|
2015-03-11 10:44:04 -04:00
|
|
|
char *colname, int location,
|
|
|
|
|
int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate);
|
2006-03-14 17:48:25 -05:00
|
|
|
extern Node *colNameToVar(ParseState *pstate, char *colname, bool localonly,
|
2006-10-03 20:30:14 -04:00
|
|
|
int location);
|
2009-01-22 15:16:10 -05:00
|
|
|
extern void markVarForSelectPriv(ParseState *pstate, Var *var,
|
2009-06-11 10:49:15 -04:00
|
|
|
RangeTblEntry *rte);
|
2008-09-01 16:42:46 -04:00
|
|
|
extern Relation parserOpenTable(ParseState *pstate, const RangeVar *relation,
|
2009-06-11 10:49:15 -04:00
|
|
|
int lockmode);
|
1998-09-01 00:40:42 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntry(ParseState *pstate,
|
2002-03-21 21:56:37 -05:00
|
|
|
RangeVar *relation,
|
|
|
|
|
Alias *alias,
|
|
|
|
|
bool inh,
|
|
|
|
|
bool inFromCl);
|
|
|
|
|
extern RangeTblEntry *addRangeTableEntryForRelation(ParseState *pstate,
|
2005-04-13 12:50:55 -04:00
|
|
|
Relation rel,
|
2002-09-04 16:31:48 -04:00
|
|
|
Alias *alias,
|
|
|
|
|
bool inh,
|
|
|
|
|
bool inFromCl);
|
2000-09-29 14:21:41 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForSubquery(ParseState *pstate,
|
2001-03-21 23:01:46 -05:00
|
|
|
Query *subquery,
|
2002-03-21 11:02:16 -05:00
|
|
|
Alias *alias,
|
2012-08-07 19:02:54 -04:00
|
|
|
bool lateral,
|
2001-03-21 23:01:46 -05:00
|
|
|
bool inFromCl);
|
2002-05-12 16:10:05 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForFunction(ParseState *pstate,
|
Support multi-argument UNNEST(), and TABLE() syntax for multiple functions.
This patch adds the ability to write TABLE( function1(), function2(), ...)
as a single FROM-clause entry. The result is the concatenation of the
first row from each function, followed by the second row from each
function, etc; with NULLs inserted if any function produces fewer rows than
others. This is believed to be a much more useful behavior than what
Postgres currently does with multiple SRFs in a SELECT list.
This syntax also provides a reasonable way to combine use of column
definition lists with WITH ORDINALITY: put the column definition list
inside TABLE(), where it's clear that it doesn't control the ordinality
column as well.
Also implement SQL-compliant multiple-argument UNNEST(), by turning
UNNEST(a,b,c) into TABLE(unnest(a), unnest(b), unnest(c)).
The SQL standard specifies TABLE() with only a single function, not
multiple functions, and it seems to require an implicit UNNEST() which is
not what this patch does. There may be something wrong with that reading
of the spec, though, because if it's right then the spec's TABLE() is just
a pointless alternative spelling of UNNEST(). After further review of
that, we might choose to adopt a different syntax for what this patch does,
but in any case this functionality seems clearly worthwhile.
Andrew Gierth, reviewed by Zoltán Böszörményi and Heikki Linnakangas, and
significantly revised by me
2013-11-21 19:37:02 -05:00
|
|
|
List *funcnames,
|
|
|
|
|
List *funcexprs,
|
|
|
|
|
List *coldeflists,
|
2002-09-04 16:31:48 -04:00
|
|
|
RangeFunction *rangefunc,
|
2012-08-07 19:02:54 -04:00
|
|
|
bool lateral,
|
2002-09-04 16:31:48 -04:00
|
|
|
bool inFromCl);
|
2006-08-01 21:59:48 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForValues(ParseState *pstate,
|
|
|
|
|
List *exprs,
|
Fix reporting of column typmods for multi-row VALUES constructs.
expandRTE() and get_rte_attribute_type() reported the exprType() and
exprTypmod() values of the expressions in the first row of the VALUES as
being the column type/typmod returned by the VALUES RTE. That's fine for
the data type, since we coerce all expressions in a column to have the same
common type. But we don't coerce them to have a common typmod, so it was
possible for rows after the first one to return values that violate the
claimed column typmod. This leads to the incorrect result seen in bug
#14448 from Hassan Mahmood, as well as some other corner-case misbehaviors.
The desired behavior is the same as we use in other type-unification
cases: report the common typmod if there is one, but otherwise return -1
indicating no particular constraint. It's cheap for transformValuesClause
to determine the common typmod while transforming a multi-row VALUES, but
it'd be less cheap for expandRTE() and get_rte_attribute_type() to
re-determine that info every time they're asked --- possibly a lot less
cheap, if the VALUES has many rows. Therefore, the best fix is to record
the common typmods explicitly in a list in the VALUES RTE, as we were
already doing for column collations. This looks quite a bit like what
we're doing for CTE RTEs, so we can save a little bit of space and code by
unifying the representation for those two RTE types. They both now share
coltypes/coltypmods/colcollations fields. (At some point it might seem
desirable to populate those fields for all RTE types; but right now it
looks like constructing them for other RTE types would add more code and
cycles than it would save.)
The RTE change requires a catversion bump, so this fix is only usable
in HEAD. If we fix this at all in the back branches, the patch will
need to look quite different.
Report: https://postgr.es/m/20161205143037.4377.60754@wrigleys.postgresql.org
Discussion: https://postgr.es/m/27429.1480968538@sss.pgh.pa.us
2016-12-08 11:40:02 -05:00
|
|
|
List *coltypes,
|
|
|
|
|
List *coltypmods,
|
|
|
|
|
List *colcollations,
|
2006-08-01 21:59:48 -04:00
|
|
|
Alias *alias,
|
2012-08-19 14:12:16 -04:00
|
|
|
bool lateral,
|
2006-08-01 21:59:48 -04:00
|
|
|
bool inFromCl);
|
2017-03-08 10:39:37 -05:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForTableFunc(ParseState *pstate,
|
|
|
|
|
TableFunc *tf,
|
|
|
|
|
Alias *alias,
|
|
|
|
|
bool lateral,
|
|
|
|
|
bool inFromCl);
|
2002-03-11 19:52:10 -05:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate,
|
|
|
|
|
List *colnames,
|
|
|
|
|
JoinType jointype,
|
2002-04-28 15:54:29 -04:00
|
|
|
List *aliasvars,
|
2002-03-21 11:02:16 -05:00
|
|
|
Alias *alias,
|
2002-03-11 19:52:10 -05:00
|
|
|
bool inFromCl);
|
2008-10-04 17:56:55 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForCTE(ParseState *pstate,
|
|
|
|
|
CommonTableExpr *cte,
|
|
|
|
|
Index levelsup,
|
2011-02-25 18:56:23 -05:00
|
|
|
RangeVar *rv,
|
2008-10-04 17:56:55 -04:00
|
|
|
bool inFromCl);
|
2017-04-01 00:17:18 -04:00
|
|
|
extern RangeTblEntry *addRangeTableEntryForENR(ParseState *pstate,
|
|
|
|
|
RangeVar *rv,
|
|
|
|
|
bool inFromCl);
|
2009-10-27 13:11:18 -04:00
|
|
|
extern bool isLockedRefname(ParseState *pstate, const char *refname);
|
2001-02-14 16:35:07 -05:00
|
|
|
extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
|
2005-06-04 20:38:11 -04:00
|
|
|
bool addToJoinList,
|
|
|
|
|
bool addToRelNameSpace, bool addToVarNameSpace);
|
2015-03-26 14:03:19 -04:00
|
|
|
extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) pg_attribute_noreturn();
|
2012-08-07 19:02:54 -04:00
|
|
|
extern void errorMissingColumn(ParseState *pstate,
|
2015-05-23 21:35:49 -04:00
|
|
|
char *relname, char *colname, int location) pg_attribute_noreturn();
|
2005-06-04 15:19:42 -04:00
|
|
|
extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
|
2008-09-01 16:42:46 -04:00
|
|
|
int location, bool include_dropped,
|
2004-08-29 01:07:03 -04:00
|
|
|
List **colnames, List **colvars);
|
2005-06-04 15:19:42 -04:00
|
|
|
extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte,
|
2008-09-01 16:42:46 -04:00
|
|
|
int rtindex, int sublevels_up, int location);
|
2002-08-02 14:15:10 -04:00
|
|
|
extern int attnameAttNum(Relation rd, const char *attname, bool sysColOK);
|
2001-10-23 13:39:03 -04:00
|
|
|
extern Name attnumAttName(Relation rd, int attid);
|
1998-02-25 23:46:47 -05:00
|
|
|
extern Oid attnumTypeId(Relation rd, int attid);
|
2011-04-11 21:32:53 -04:00
|
|
|
extern Oid attnumCollationId(Relation rd, int attid);
|
Clean up the mess around EXPLAIN and materialized views.
Revert the matview-related changes in explain.c's API, as per recent
complaint from Robert Haas. The reason for these appears to have been
principally some ill-considered choices around having intorel_startup do
what ought to be parse-time checking, plus a poor arrangement for passing
it the view parsetree it needs to store into pg_rewrite when creating a
materialized view. Do the latter by having parse analysis stick a copy
into the IntoClause, instead of doing it at runtime. (On the whole,
I seriously question the choice to represent CREATE MATERIALIZED VIEW as a
variant of SELECT INTO/CREATE TABLE AS, because that means injecting even
more complexity into what was already a horrid legacy kluge. However,
I didn't go so far as to rethink that choice ... yet.)
I also moved several error checks into matview parse analysis, and
made the check for external Params in a matview more accurate.
In passing, clean things up a bit more around interpretOidsOption(),
and fix things so that we can use that to force no-oids for views,
sequences, etc, thereby eliminating the need to cons up "oids = false"
options when creating them.
catversion bump due to change in IntoClause. (I wonder though if we
really need readfuncs/outfuncs support for IntoClause anymore.)
2013-04-12 19:25:20 -04:00
|
|
|
extern bool isQueryUsingTempRelation(Query *query);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2001-11-05 12:46:40 -05:00
|
|
|
#endif /* PARSE_RELATION_H */
|