Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita77e32d

Browse files
committed
Apply the core parts of Dennis Bjorklund's patch to allow function
parameters to be declared with names. pg_proc has a column to storenames, and CREATE FUNCTION can insert data into it, but that's all asyet. I need to do more work on the pg_dump and plpgsql portions of thepatch before committing those, but I thought I'd get the bulky changesin before the tree drifts under me.initdb forced due to pg_proc change.
1 parent488f278 commita77e32d

File tree

20 files changed

+1848
-1657
lines changed

20 files changed

+1848
-1657
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.81 2003/12/06 23:10:21 joe Exp $
3+
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.82 2004/01/06 23:55:18 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -2798,6 +2798,17 @@
27982798
<entry>An array with the data types of the function arguments</entry>
27992799
</row>
28002800

2801+
<row>
2802+
<entry><structfield>proargnames</structfield></entry>
2803+
<entry><type>text[]</type></entry>
2804+
<entry></entry>
2805+
<entry>
2806+
An array with the names of the function arguments.
2807+
Arguments without a name are set to empty strings in the array.
2808+
If none of the arguments have a name, this field may be null.
2809+
</entry>
2810+
</row>
2811+
28012812
<row>
28022813
<entry><structfield>prosrc</structfield></entry>
28032814
<entry><type>text</type></entry>

‎src/backend/bootstrap/bootstrap.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.173 2004/01/06 23:15:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.174 2004/01/06 23:55:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -130,6 +130,7 @@ static struct typinfo Procid[] = {
130130
{"oidvector",OIDVECTOROID,0,INDEX_MAX_KEYS*4,F_OIDVECTORIN,F_OIDVECTOROUT},
131131
{"smgr",210,0,2,F_SMGRIN,F_SMGROUT},
132132
{"_int4",1007,INT4OID,-1,F_ARRAY_IN,F_ARRAY_OUT},
133+
{"_text",1009,TEXTOID,-1,F_ARRAY_IN,F_ARRAY_OUT},
133134
{"_aclitem",1034,1033,-1,F_ARRAY_IN,F_ARRAY_OUT}
134135
};
135136

@@ -690,6 +691,11 @@ DefineAttr(char *name, char *type, int attnum)
690691
attrtypes[attnum]->attbyval=Ap->am_typ.typbyval;
691692
attrtypes[attnum]->attstorage=Ap->am_typ.typstorage;
692693
attrtypes[attnum]->attalign=Ap->am_typ.typalign;
694+
/* if an array type, assume 1-dimensional attribute */
695+
if (Ap->am_typ.typelem!=InvalidOid&&Ap->am_typ.typlen<0)
696+
attrtypes[attnum]->attndims=1;
697+
else
698+
attrtypes[attnum]->attndims=0;
693699
}
694700
else
695701
{
@@ -729,7 +735,14 @@ DefineAttr(char *name, char *type, int attnum)
729735
attrtypes[attnum]->attalign='i';
730736
break;
731737
}
738+
/* if an array type, assume 1-dimensional attribute */
739+
if (Procid[typeoid].elem!=InvalidOid&&attlen<0)
740+
attrtypes[attnum]->attndims=1;
741+
else
742+
attrtypes[attnum]->attndims=0;
732743
}
744+
745+
attrtypes[attnum]->attstattarget=-1;
733746
attrtypes[attnum]->attcacheoff=-1;
734747
attrtypes[attnum]->atttypmod=-1;
735748
attrtypes[attnum]->attislocal= true;

‎src/backend/catalog/pg_aggregate.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.65 2003/11/29 19:51:45 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.66 2004/01/06 23:55:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -190,7 +190,8 @@ AggregateCreate(const char *aggName,
190190
PROVOLATILE_IMMUTABLE,/* volatility (not
191191
* needed for agg) */
192192
1,/* parameterCount */
193-
fnArgs);/* parameterTypes */
193+
fnArgs,/* parameterTypes */
194+
NULL);/* parameterNames */
194195

195196
/*
196197
* Okay to create the pg_aggregate entry.

‎src/backend/catalog/pg_proc.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.110 2003/11/29 19:51:46 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.111 2004/01/06 23:55:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,6 +42,9 @@ Datumfmgr_internal_validator(PG_FUNCTION_ARGS);
4242
Datumfmgr_c_validator(PG_FUNCTION_ARGS);
4343
Datumfmgr_sql_validator(PG_FUNCTION_ARGS);
4444

45+
staticDatumcreate_parameternames_array(intparameterCount,
46+
constchar*parameterNames[]);
47+
4548

4649
/* ----------------------------------------------------------------
4750
*ProcedureCreate
@@ -62,7 +65,8 @@ ProcedureCreate(const char *procedureName,
6265
boolisStrict,
6366
charvolatility,
6467
intparameterCount,
65-
constOid*parameterTypes)
68+
constOid*parameterTypes,
69+
constchar*parameterNames[])
6670
{
6771
inti;
6872
Relationrel;
@@ -72,6 +76,7 @@ ProcedureCreate(const char *procedureName,
7276
Datumvalues[Natts_pg_proc];
7377
charreplaces[Natts_pg_proc];
7478
Oidtypev[FUNC_MAX_ARGS];
79+
Datumnamesarray;
7580
Oidrelid;
7681
NameDataprocname;
7782
TupleDesctupDesc;
@@ -122,6 +127,9 @@ ProcedureCreate(const char *procedureName,
122127
if (parameterCount>0)
123128
memcpy(typev,parameterTypes,parameterCount*sizeof(Oid));
124129

130+
/* Process param names, if given */
131+
namesarray=create_parameternames_array(parameterCount,parameterNames);
132+
125133
if (languageObjectId==SQLlanguageId)
126134
{
127135
/*
@@ -197,6 +205,9 @@ ProcedureCreate(const char *procedureName,
197205
values[i++]=UInt16GetDatum(parameterCount);/* pronargs */
198206
values[i++]=ObjectIdGetDatum(returnType);/* prorettype */
199207
values[i++]=PointerGetDatum(typev);/* proargtypes */
208+
values[i++]=namesarray;/* proargnames */
209+
if (namesarray==PointerGetDatum(NULL))
210+
nulls[Anum_pg_proc_proargnames-1]='n';
200211
values[i++]=DirectFunctionCall1(textin,/* prosrc */
201212
CStringGetDatum(prosrc));
202213
values[i++]=DirectFunctionCall1(textin,/* probin */
@@ -334,6 +345,43 @@ ProcedureCreate(const char *procedureName,
334345
returnretval;
335346
}
336347

348+
349+
/*
350+
* create_parameternames_array - build proargnames value from an array
351+
* of C strings. Returns a NULL pointer if no names provided.
352+
*/
353+
staticDatum
354+
create_parameternames_array(intparameterCount,constchar*parameterNames[])
355+
{
356+
Datumelems[FUNC_MAX_ARGS];
357+
boolfound= false;
358+
ArrayType*names;
359+
inti;
360+
361+
if (!parameterNames)
362+
returnPointerGetDatum(NULL);
363+
364+
for (i=0;i<parameterCount;i++)
365+
{
366+
constchar*s=parameterNames[i];
367+
368+
if (s&&*s)
369+
found= true;
370+
else
371+
s="";
372+
373+
elems[i]=DirectFunctionCall1(textin,CStringGetDatum(s));
374+
}
375+
376+
if (!found)
377+
returnPointerGetDatum(NULL);
378+
379+
names=construct_array(elems,parameterCount,TEXTOID,-1, false,'i');
380+
381+
returnPointerGetDatum(names);
382+
}
383+
384+
337385
/*
338386
* check_sql_fn_retval() -- check return value of a list of sql parse trees.
339387
*

‎src/backend/commands/functioncmds.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.42 2003/11/29 19:51:47 pgsql Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.43 2004/01/06 23:55:18 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* These routines take the parse tree and pick out the
@@ -130,19 +130,22 @@ compute_return_type(TypeName *returnType, Oid languageOid,
130130
}
131131

132132
/*
133-
* Interpret theargument-types list of the CREATE FUNCTION statement.
133+
* Interpret theparameter list of the CREATE FUNCTION statement.
134134
*/
135135
staticint
136-
compute_parameter_types(List*argTypes,OidlanguageOid,
137-
Oid*parameterTypes)
136+
examine_parameter_list(List*parameter,OidlanguageOid,
137+
Oid*parameterTypes,constchar*parameterNames[])
138138
{
139139
intparameterCount=0;
140140
List*x;
141141

142142
MemSet(parameterTypes,0,FUNC_MAX_ARGS*sizeof(Oid));
143-
foreach(x,argTypes)
143+
MemSet(parameterNames,0,FUNC_MAX_ARGS*sizeof(char*));
144+
145+
foreach(x,parameter)
144146
{
145-
TypeName*t= (TypeName*)lfirst(x);
147+
FunctionParameter*fp= (FunctionParameter*)lfirst(x);
148+
TypeName*t=fp->argType;
146149
Oidtoid;
147150

148151
if (parameterCount >=FUNC_MAX_ARGS)
@@ -182,7 +185,11 @@ compute_parameter_types(List *argTypes, Oid languageOid,
182185
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
183186
errmsg("functions cannot accept set arguments")));
184187

185-
parameterTypes[parameterCount++]=toid;
188+
parameterTypes[parameterCount]=toid;
189+
190+
parameterNames[parameterCount]=fp->name;
191+
192+
parameterCount++;
186193
}
187194

188195
returnparameterCount;
@@ -402,6 +409,7 @@ CreateFunction(CreateFunctionStmt *stmt)
402409
AclResultaclresult;
403410
intparameterCount;
404411
OidparameterTypes[FUNC_MAX_ARGS];
412+
constchar*parameterNames[FUNC_MAX_ARGS];
405413
boolisStrict,
406414
security;
407415
charvolatility;
@@ -480,8 +488,8 @@ CreateFunction(CreateFunctionStmt *stmt)
480488
compute_return_type(stmt->returnType,languageOid,
481489
&prorettype,&returnsSet);
482490

483-
parameterCount=compute_parameter_types(stmt->argTypes,languageOid,
484-
parameterTypes);
491+
parameterCount=examine_parameter_list(stmt->parameters,languageOid,
492+
parameterTypes,parameterNames);
485493

486494
compute_attributes_with_style(stmt->withClause,&isStrict,&volatility);
487495

@@ -527,7 +535,8 @@ CreateFunction(CreateFunctionStmt *stmt)
527535
isStrict,
528536
volatility,
529537
parameterCount,
530-
parameterTypes);
538+
parameterTypes,
539+
parameterNames);
531540
}
532541

533542

‎src/backend/nodes/copyfuncs.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.274 2004/01/0604:31:01 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.275 2004/01/0623:55:18 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1878,14 +1878,25 @@ _copyCreateFunctionStmt(CreateFunctionStmt *from)
18781878

18791879
COPY_SCALAR_FIELD(replace);
18801880
COPY_NODE_FIELD(funcname);
1881-
COPY_NODE_FIELD(argTypes);
1881+
COPY_NODE_FIELD(parameters);
18821882
COPY_NODE_FIELD(returnType);
18831883
COPY_NODE_FIELD(options);
18841884
COPY_NODE_FIELD(withClause);
18851885

18861886
returnnewnode;
18871887
}
18881888

1889+
staticFunctionParameter*
1890+
_copyFunctionParameter(FunctionParameter*from)
1891+
{
1892+
FunctionParameter*newnode=makeNode(FunctionParameter);
1893+
1894+
COPY_STRING_FIELD(name);
1895+
COPY_NODE_FIELD(argType);
1896+
1897+
returnnewnode;
1898+
}
1899+
18891900
staticRemoveAggrStmt*
18901901
_copyRemoveAggrStmt(RemoveAggrStmt*from)
18911902
{
@@ -2788,6 +2799,9 @@ copyObject(void *from)
27882799
caseT_CreateFunctionStmt:
27892800
retval=_copyCreateFunctionStmt(from);
27902801
break;
2802+
caseT_FunctionParameter:
2803+
retval=_copyFunctionParameter(from);
2804+
break;
27912805
caseT_RemoveAggrStmt:
27922806
retval=_copyRemoveAggrStmt(from);
27932807
break;

‎src/backend/nodes/equalfuncs.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.212 2004/01/05 05:07:35 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.213 2004/01/06 23:55:18 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -884,14 +884,23 @@ _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
884884
{
885885
COMPARE_SCALAR_FIELD(replace);
886886
COMPARE_NODE_FIELD(funcname);
887-
COMPARE_NODE_FIELD(argTypes);
887+
COMPARE_NODE_FIELD(parameters);
888888
COMPARE_NODE_FIELD(returnType);
889889
COMPARE_NODE_FIELD(options);
890890
COMPARE_NODE_FIELD(withClause);
891891

892892
return true;
893893
}
894894

895+
staticbool
896+
_equalFunctionParameter(FunctionParameter*a,FunctionParameter*b)
897+
{
898+
COMPARE_STRING_FIELD(name);
899+
COMPARE_NODE_FIELD(argType);
900+
901+
return true;
902+
}
903+
895904
staticbool
896905
_equalRemoveAggrStmt(RemoveAggrStmt*a,RemoveAggrStmt*b)
897906
{
@@ -1868,6 +1877,9 @@ equal(void *a, void *b)
18681877
caseT_CreateFunctionStmt:
18691878
retval=_equalCreateFunctionStmt(a,b);
18701879
break;
1880+
caseT_FunctionParameter:
1881+
retval=_equalFunctionParameter(a,b);
1882+
break;
18711883
caseT_RemoveAggrStmt:
18721884
retval=_equalRemoveAggrStmt(a,b);
18731885
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp