Skip to content

Commit 07f9682

Browse files
committed
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.
1 parent ac1a3dc commit 07f9682

File tree

12 files changed

+91
-119
lines changed

12 files changed

+91
-119
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.51 2002/08/02 18:15:04 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.52 2002/08/05 02:30:46 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -3201,8 +3201,9 @@
32013201
<entry>
32023202
<structfield>typtype</structfield> is <literal>b</literal> for
32033203
a base type, <literal>c</literal> for a complex type (i.e.,
3204-
a table's row type), or <literal>d</literal> for a derived type (i.e.,
3205-
a domain). See also <structfield>typrelid</structfield>
3204+
a table's row type), <literal>d</literal> for a derived type (i.e.,
3205+
a domain), or <literal>p</literal> for a pseudo-type. See also
3206+
<structfield>typrelid</structfield>
32063207
and <structfield>typbasetype</structfield>.
32073208
</entry>
32083209
</row>
@@ -3235,7 +3236,7 @@
32353236
<structfield>typtype</structfield>), then this field points to
32363237
the <structfield>pg_class</structfield> entry that defines the
32373238
corresponding table. A table could theoretically be used as a
3238-
composite data type, but this is not fully functional.
3239+
composite data type, but this is only partly functional.
32393240
Zero for non-complex types.
32403241
</entry>
32413242
</row>

src/backend/access/common/tupdesc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.84 2002/08/04 19:48:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.85 2002/08/05 02:30:49 tgl Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -24,9 +24,9 @@
2424
#include "catalog/namespace.h"
2525
#include "catalog/pg_type.h"
2626
#include "nodes/parsenodes.h"
27-
#include "parser/parse_relation.h"
2827
#include "parser/parse_type.h"
2928
#include "utils/builtins.h"
29+
#include "utils/lsyscache.h"
3030
#include "utils/syscache.h"
3131

3232

@@ -601,7 +601,7 @@ RelationNameGetTupleDesc(char *relname)
601601
TupleDesc
602602
TypeGetTupleDesc(Oid typeoid, List *colaliases)
603603
{
604-
char functyptype = typeid_get_typtype(typeoid);
604+
char functyptype = get_typtype(typeoid);
605605
TupleDesc tupdesc = NULL;
606606

607607
/*
@@ -639,15 +639,13 @@ TypeGetTupleDesc(Oid typeoid, List *colaliases)
639639

640640
if (label != NULL)
641641
namestrcpy(&(tupdesc->attrs[varattno]->attname), label);
642-
else
643-
MemSet(NameStr(tupdesc->attrs[varattno]->attname), 0, NAMEDATALEN);
644642
}
645643
}
646644
}
647645
else
648646
elog(ERROR, "Invalid return relation specified for function");
649647
}
650-
else if (functyptype == 'b')
648+
else if (functyptype == 'b' || functyptype == 'd')
651649
{
652650
/* Must be a base data type, i.e. scalar */
653651
char *attname;

src/backend/catalog/heap.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.216 2002/08/02 21:54:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.217 2002/08/05 02:30:50 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -369,18 +369,6 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids, char relkind)
369369
}
370370
}
371371

372-
/*
373-
* also, warn user if attribute to be created has an unknown typid
374-
* (usually as a result of a 'retrieve into' - jolly
375-
*/
376-
for (i = 0; i < natts; i++)
377-
{
378-
if (tupdesc->attrs[i]->atttypid == UNKNOWNOID)
379-
elog(WARNING, "Attribute '%s' has an unknown type"
380-
"\n\tProceeding with relation creation anyway",
381-
NameStr(tupdesc->attrs[i]->attname));
382-
}
383-
384372
/*
385373
* next check for repeated attribute names
386374
*/
@@ -394,6 +382,28 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids, char relkind)
394382
NameStr(tupdesc->attrs[j]->attname));
395383
}
396384
}
385+
386+
/*
387+
* We also do some checking of the attribute types here.
388+
*
389+
* Warn user, but don't fail, if column to be created has UNKNOWN type
390+
* (usually as a result of a 'retrieve into' - jolly)
391+
*
392+
* Refuse any attempt to create a pseudo-type column.
393+
*/
394+
for (i = 0; i < natts; i++)
395+
{
396+
Oid att_type = tupdesc->attrs[i]->atttypid;
397+
398+
if (att_type == UNKNOWNOID)
399+
elog(WARNING, "Attribute \"%s\" has an unknown type"
400+
"\n\tProceeding with relation creation anyway",
401+
NameStr(tupdesc->attrs[i]->attname));
402+
if (get_typtype(att_type) == 'p')
403+
elog(ERROR, "Attribute \"%s\" has pseudo-type %s",
404+
NameStr(tupdesc->attrs[i]->attname),
405+
format_type_be(att_type));
406+
}
397407
}
398408

399409
/* --------------------------------

src/backend/catalog/pg_proc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.86 2002/08/05 00:21:27 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.87 2002/08/05 02:30:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,7 +25,6 @@
2525
#include "miscadmin.h"
2626
#include "parser/parse_coerce.h"
2727
#include "parser/parse_expr.h"
28-
#include "parser/parse_relation.h"
2928
#include "parser/parse_type.h"
3029
#include "tcop/tcopprot.h"
3130
#include "utils/builtins.h"
@@ -370,7 +369,7 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
370369

371370
typerelid = typeidTypeRelid(rettype);
372371

373-
if (fn_typtype == 'b')
372+
if (fn_typtype == 'b' || fn_typtype == 'd')
374373
{
375374
/* Shouldn't have a typerelid */
376375
Assert(typerelid == InvalidOid);
@@ -592,7 +591,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
592591
prosrc = DatumGetCString(DirectFunctionCall1(textout, tmp));
593592

594593
/* check typtype to see if we have a predetermined return type */
595-
functyptype = typeid_get_typtype(proc->prorettype);
594+
functyptype = get_typtype(proc->prorettype);
596595

597596
querytree_list = pg_parse_and_rewrite(prosrc, proc->proargtypes, proc->pronargs);
598597
checkretval(proc->prorettype, functyptype, querytree_list);

src/backend/executor/functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.53 2002/08/04 19:48:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.54 2002/08/05 02:30:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -195,7 +195,7 @@ init_sql_fcache(FmgrInfo *finfo)
195195
*/
196196
fcache->typlen = typeStruct->typlen;
197197

198-
if (typeStruct->typtype == 'b')
198+
if (typeStruct->typtype == 'b' || typeStruct->typtype == 'd')
199199
{
200200
/* The return type is not a relation, so just use byval */
201201
fcache->typbyval = typeStruct->typbyval;

src/backend/executor/nodeFunctionscan.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.4 2002/08/04 19:48:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.5 2002/08/05 02:30:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,7 +31,6 @@
3131
#include "executor/nodeFunctionscan.h"
3232
#include "parser/parsetree.h"
3333
#include "parser/parse_expr.h"
34-
#include "parser/parse_relation.h"
3534
#include "parser/parse_type.h"
3635
#include "storage/lmgr.h"
3736
#include "tcop/pquery.h"
@@ -204,7 +203,7 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, Plan *parent)
204203
* Now determine if the function returns a simple or composite type,
205204
* and check/add column aliases.
206205
*/
207-
functyptype = typeid_get_typtype(funcrettype);
206+
functyptype = get_typtype(funcrettype);
208207

209208
/*
210209
* Build a suitable tupledesc representing the output rows
@@ -228,7 +227,7 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, Plan *parent)
228227
else
229228
elog(ERROR, "Invalid return relation specified for function");
230229
}
231-
else if (functyptype == 'b')
230+
else if (functyptype == 'b' || functyptype == 'd')
232231
{
233232
/*
234233
* Must be a base data type, i.e. scalar
@@ -462,7 +461,7 @@ function_getonetuple(FunctionScanState *scanstate,
462461
*/
463462
if (fn_typtype == 'p' && fn_typeid == RECORDOID)
464463
if (tupledesc_mismatch(tupdesc, slot->ttc_tupleDescriptor))
465-
elog(ERROR, "Query specified return tuple and actual"
464+
elog(ERROR, "Query-specified return tuple and actual"
466465
" function return tuple do not match");
467466
}
468467
else

src/backend/parser/gram.y

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.355 2002/08/04 19:48:09 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.356 2002/08/05 02:30:50 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -203,7 +203,7 @@ static void doNegateFloat(Value *v);
203203
%type <chr> TriggerOneEvent
204204

205205
%type <list> stmtblock, stmtmulti,
206-
OptTableElementList, OptInherit, definition,
206+
OptTableElementList, TableElementList, OptInherit, definition,
207207
opt_distinct, opt_definition, func_args,
208208
func_args_list, func_as, createfunc_opt_list
209209
oper_argtypes, RuleActionList, RuleActionMulti,
@@ -216,7 +216,7 @@ static void doNegateFloat(Value *v);
216216
insert_target_list, def_list, opt_indirection,
217217
group_clause, TriggerFuncArgs, select_limit,
218218
opt_select_limit, opclass_item_list, trans_options,
219-
tableFuncElementList
219+
TableFuncElementList, OptTableFuncElementList
220220

221221
%type <range> into_clause, OptTempTableName
222222

@@ -257,8 +257,8 @@ static void doNegateFloat(Value *v);
257257

258258
%type <vsetstmt> set_rest
259259

260-
%type <node> OptTableElement, ConstraintElem, tableFuncElement
261-
%type <node> columnDef, tableFuncColumnDef
260+
%type <node> TableElement, ConstraintElem, TableFuncElement
261+
%type <node> columnDef
262262
%type <defelt> def_elem
263263
%type <node> def_arg, columnElem, where_clause, insert_column_item,
264264
a_expr, b_expr, c_expr, r_expr, AexprConst,
@@ -1428,24 +1428,22 @@ OptTemp: TEMPORARY { $$ = TRUE; }
14281428
;
14291429

14301430
OptTableElementList:
1431-
OptTableElementList ',' OptTableElement
1431+
TableElementList { $$ = $1; }
1432+
| /*EMPTY*/ { $$ = NIL; }
1433+
;
1434+
1435+
TableElementList:
1436+
TableElementList ',' TableElement
14321437
{
1433-
if ($3 != NULL)
1434-
$$ = lappend($1, $3);
1435-
else
1436-
$$ = $1;
1438+
$$ = lappend($1, $3);
14371439
}
1438-
| OptTableElement
1440+
| TableElement
14391441
{
1440-
if ($1 != NULL)
1441-
$$ = makeList1($1);
1442-
else
1443-
$$ = NIL;
1442+
$$ = makeList1($1);
14441443
}
1445-
| /*EMPTY*/ { $$ = NIL; }
14461444
;
14471445

1448-
OptTableElement:
1446+
TableElement:
14491447
columnDef { $$ = $1; }
14501448
| TableLikeClause { $$ = $1; }
14511449
| TableConstraint { $$ = $1; }
@@ -1877,7 +1875,7 @@ CreateSeqStmt:
18771875
;
18781876

18791877
OptSeqList: OptSeqList OptSeqElem { $$ = lappend($1, $2); }
1880-
| { $$ = NIL; }
1878+
| /*EMPTY*/ { $$ = NIL; }
18811879
;
18821880

18831881
OptSeqElem: CACHE NumericOnly
@@ -4452,14 +4450,14 @@ table_ref: relation_expr
44524450
n->coldeflist = NIL;
44534451
$$ = (Node *) n;
44544452
}
4455-
| func_table AS '(' tableFuncElementList ')'
4453+
| func_table AS '(' OptTableFuncElementList ')'
44564454
{
44574455
RangeFunction *n = makeNode(RangeFunction);
44584456
n->funccallnode = $1;
44594457
n->coldeflist = $4;
44604458
$$ = (Node *) n;
44614459
}
4462-
| func_table AS ColId '(' tableFuncElementList ')'
4460+
| func_table AS ColId '(' OptTableFuncElementList ')'
44634461
{
44644462
RangeFunction *n = makeNode(RangeFunction);
44654463
Alias *a = makeNode(Alias);
@@ -4469,7 +4467,7 @@ table_ref: relation_expr
44694467
n->coldeflist = $5;
44704468
$$ = (Node *) n;
44714469
}
4472-
| func_table ColId '(' tableFuncElementList ')'
4470+
| func_table ColId '(' OptTableFuncElementList ')'
44734471
{
44744472
RangeFunction *n = makeNode(RangeFunction);
44754473
Alias *a = makeNode(Alias);
@@ -4733,29 +4731,23 @@ where_clause:
47334731
;
47344732

47354733

4736-
tableFuncElementList:
4737-
tableFuncElementList ',' tableFuncElement
4734+
OptTableFuncElementList:
4735+
TableFuncElementList { $$ = $1; }
4736+
| /*EMPTY*/ { $$ = NIL; }
4737+
;
4738+
4739+
TableFuncElementList:
4740+
TableFuncElementList ',' TableFuncElement
47384741
{
4739-
if ($3 != NULL)
4740-
$$ = lappend($1, $3);
4741-
else
4742-
$$ = $1;
4742+
$$ = lappend($1, $3);
47434743
}
4744-
| tableFuncElement
4744+
| TableFuncElement
47454745
{
4746-
if ($1 != NULL)
4747-
$$ = makeList1($1);
4748-
else
4749-
$$ = NIL;
4746+
$$ = makeList1($1);
47504747
}
4751-
| /*EMPTY*/ { $$ = NIL; }
4752-
;
4753-
4754-
tableFuncElement:
4755-
tableFuncColumnDef { $$ = $1; }
47564748
;
47574749

4758-
tableFuncColumnDef: ColId Typename
4750+
TableFuncElement: ColId Typename
47594751
{
47604752
ColumnDef *n = makeNode(ColumnDef);
47614753
n->colname = $1;

0 commit comments

Comments
 (0)