mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Preliminary code review for anonymous-composite-types patch: fix breakage
of functions returning domain types, update documentation for typtype, move get_typtype to lsyscache.c (actually, resurrect the old version), add defense against creating pseudo-typed table columns, fix some bogus list-parsing in grammar. Issues remain with respect to alias handling and type checking; Joe is on those.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.355 2002/08/04 19:48:09 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.356 2002/08/05 02:30:50 tgl Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -203,7 +203,7 @@ static void doNegateFloat(Value *v);
|
||||
%type <chr> TriggerOneEvent
|
||||
|
||||
%type <list> stmtblock, stmtmulti,
|
||||
OptTableElementList, OptInherit, definition,
|
||||
OptTableElementList, TableElementList, OptInherit, definition,
|
||||
opt_distinct, opt_definition, func_args,
|
||||
func_args_list, func_as, createfunc_opt_list
|
||||
oper_argtypes, RuleActionList, RuleActionMulti,
|
||||
@@ -216,7 +216,7 @@ static void doNegateFloat(Value *v);
|
||||
insert_target_list, def_list, opt_indirection,
|
||||
group_clause, TriggerFuncArgs, select_limit,
|
||||
opt_select_limit, opclass_item_list, trans_options,
|
||||
tableFuncElementList
|
||||
TableFuncElementList, OptTableFuncElementList
|
||||
|
||||
%type <range> into_clause, OptTempTableName
|
||||
|
||||
@@ -257,8 +257,8 @@ static void doNegateFloat(Value *v);
|
||||
|
||||
%type <vsetstmt> set_rest
|
||||
|
||||
%type <node> OptTableElement, ConstraintElem, tableFuncElement
|
||||
%type <node> columnDef, tableFuncColumnDef
|
||||
%type <node> TableElement, ConstraintElem, TableFuncElement
|
||||
%type <node> columnDef
|
||||
%type <defelt> def_elem
|
||||
%type <node> def_arg, columnElem, where_clause, insert_column_item,
|
||||
a_expr, b_expr, c_expr, r_expr, AexprConst,
|
||||
@@ -1428,24 +1428,22 @@ OptTemp: TEMPORARY { $$ = TRUE; }
|
||||
;
|
||||
|
||||
OptTableElementList:
|
||||
OptTableElementList ',' OptTableElement
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = lappend($1, $3);
|
||||
else
|
||||
$$ = $1;
|
||||
}
|
||||
| OptTableElement
|
||||
{
|
||||
if ($1 != NULL)
|
||||
$$ = makeList1($1);
|
||||
else
|
||||
$$ = NIL;
|
||||
}
|
||||
TableElementList { $$ = $1; }
|
||||
| /*EMPTY*/ { $$ = NIL; }
|
||||
;
|
||||
|
||||
OptTableElement:
|
||||
TableElementList:
|
||||
TableElementList ',' TableElement
|
||||
{
|
||||
$$ = lappend($1, $3);
|
||||
}
|
||||
| TableElement
|
||||
{
|
||||
$$ = makeList1($1);
|
||||
}
|
||||
;
|
||||
|
||||
TableElement:
|
||||
columnDef { $$ = $1; }
|
||||
| TableLikeClause { $$ = $1; }
|
||||
| TableConstraint { $$ = $1; }
|
||||
@@ -1877,7 +1875,7 @@ CreateSeqStmt:
|
||||
;
|
||||
|
||||
OptSeqList: OptSeqList OptSeqElem { $$ = lappend($1, $2); }
|
||||
| { $$ = NIL; }
|
||||
| /*EMPTY*/ { $$ = NIL; }
|
||||
;
|
||||
|
||||
OptSeqElem: CACHE NumericOnly
|
||||
@@ -4452,14 +4450,14 @@ table_ref: relation_expr
|
||||
n->coldeflist = NIL;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| func_table AS '(' tableFuncElementList ')'
|
||||
| func_table AS '(' OptTableFuncElementList ')'
|
||||
{
|
||||
RangeFunction *n = makeNode(RangeFunction);
|
||||
n->funccallnode = $1;
|
||||
n->coldeflist = $4;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| func_table AS ColId '(' tableFuncElementList ')'
|
||||
| func_table AS ColId '(' OptTableFuncElementList ')'
|
||||
{
|
||||
RangeFunction *n = makeNode(RangeFunction);
|
||||
Alias *a = makeNode(Alias);
|
||||
@@ -4469,7 +4467,7 @@ table_ref: relation_expr
|
||||
n->coldeflist = $5;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| func_table ColId '(' tableFuncElementList ')'
|
||||
| func_table ColId '(' OptTableFuncElementList ')'
|
||||
{
|
||||
RangeFunction *n = makeNode(RangeFunction);
|
||||
Alias *a = makeNode(Alias);
|
||||
@@ -4733,29 +4731,23 @@ where_clause:
|
||||
;
|
||||
|
||||
|
||||
tableFuncElementList:
|
||||
tableFuncElementList ',' tableFuncElement
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = lappend($1, $3);
|
||||
else
|
||||
$$ = $1;
|
||||
}
|
||||
| tableFuncElement
|
||||
{
|
||||
if ($1 != NULL)
|
||||
$$ = makeList1($1);
|
||||
else
|
||||
$$ = NIL;
|
||||
}
|
||||
OptTableFuncElementList:
|
||||
TableFuncElementList { $$ = $1; }
|
||||
| /*EMPTY*/ { $$ = NIL; }
|
||||
;
|
||||
|
||||
tableFuncElement:
|
||||
tableFuncColumnDef { $$ = $1; }
|
||||
TableFuncElementList:
|
||||
TableFuncElementList ',' TableFuncElement
|
||||
{
|
||||
$$ = lappend($1, $3);
|
||||
}
|
||||
| TableFuncElement
|
||||
{
|
||||
$$ = makeList1($1);
|
||||
}
|
||||
;
|
||||
|
||||
tableFuncColumnDef: ColId Typename
|
||||
TableFuncElement: ColId Typename
|
||||
{
|
||||
ColumnDef *n = makeNode(ColumnDef);
|
||||
n->colname = $1;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.72 2002/08/04 19:48:10 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.73 2002/08/05 02:30:50 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -727,7 +727,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
* Now determine if the function returns a simple or composite type,
|
||||
* and check/add column aliases.
|
||||
*/
|
||||
functyptype = typeid_get_typtype(funcrettype);
|
||||
functyptype = get_typtype(funcrettype);
|
||||
|
||||
if (functyptype == 'c')
|
||||
{
|
||||
@@ -776,7 +776,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
elog(ERROR, "Invalid return relation specified for function %s",
|
||||
funcname);
|
||||
}
|
||||
else if (functyptype == 'b')
|
||||
else if (functyptype == 'b' || functyptype == 'd')
|
||||
{
|
||||
/*
|
||||
* Must be a base data type, i.e. scalar.
|
||||
@@ -1080,7 +1080,7 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
{
|
||||
/* Function RTE */
|
||||
Oid funcrettype = exprType(rte->funcexpr);
|
||||
char functyptype = typeid_get_typtype(funcrettype);
|
||||
char functyptype = get_typtype(funcrettype);
|
||||
List *coldeflist = rte->coldeflist;
|
||||
|
||||
/*
|
||||
@@ -1091,7 +1091,6 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
Oid funcrelid = typeidTypeRelid(funcrettype);
|
||||
if (OidIsValid(funcrelid))
|
||||
{
|
||||
|
||||
/*
|
||||
* Composite data type, i.e. a table's row type
|
||||
* Same as ordinary relation RTE
|
||||
@@ -1142,7 +1141,7 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
elog(ERROR, "Invalid return relation specified"
|
||||
" for function");
|
||||
}
|
||||
else if (functyptype == 'b')
|
||||
else if (functyptype == 'b' || functyptype == 'd')
|
||||
{
|
||||
/*
|
||||
* Must be a base data type, i.e. scalar
|
||||
@@ -1392,7 +1391,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
{
|
||||
/* Function RTE */
|
||||
Oid funcrettype = exprType(rte->funcexpr);
|
||||
char functyptype = typeid_get_typtype(funcrettype);
|
||||
char functyptype = get_typtype(funcrettype);
|
||||
List *coldeflist = rte->coldeflist;
|
||||
|
||||
/*
|
||||
@@ -1436,7 +1435,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
elog(ERROR, "Invalid return relation specified"
|
||||
" for function");
|
||||
}
|
||||
else if (functyptype == 'b')
|
||||
else if (functyptype == 'b' || functyptype == 'd')
|
||||
{
|
||||
/*
|
||||
* Must be a base data type, i.e. scalar
|
||||
@@ -1687,28 +1686,3 @@ warnAutoRange(ParseState *pstate, RangeVar *relation)
|
||||
pstate->parentParseState != NULL ? " in subquery" : "",
|
||||
relation->relname);
|
||||
}
|
||||
|
||||
char
|
||||
typeid_get_typtype(Oid typeid)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type typeStruct;
|
||||
char result;
|
||||
|
||||
/*
|
||||
* determine if the function returns a simple, named composite,
|
||||
* or anonymous composite type
|
||||
*/
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(typeid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "cache lookup for type %u failed", typeid);
|
||||
typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
result = typeStruct->typtype;
|
||||
|
||||
ReleaseSysCache(typeTuple);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user