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

Commit2e5fda7

Browse files
committed
DROP AGGREGATE and COMMENT ON AGGREGATE now accept the expected syntax
'aggname (aggtype)'. The old syntax 'aggname aggtype' is still acceptedfor backwards compatibility. Fix pg_dump, which was actually broken formost cases of user-defined aggregates. Clean up error messages associatedwith these commands.
1 parent16def00 commit2e5fda7

File tree

14 files changed

+133
-153
lines changed

14 files changed

+133
-153
lines changed

‎doc/src/sgml/ref/comment.sgml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.9 2001/09/0312:57:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/comment.sgml,v 1.10 2001/10/0320:54:20 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -25,11 +25,10 @@ Postgres documentation
2525
<synopsis>
2626
COMMENT ON
2727
[
28-
[ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
29-
<replaceable class="PARAMETER">object_name</replaceable> |
30-
COLUMN <replaceable class="PARAMETER">table_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable>|
31-
AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> <replaceable class="PARAMETER">agg_type</replaceable>|
32-
FUNCTION <replaceable class="PARAMETER">func_name</replaceable> (<replaceable class="PARAMETER">arg1</replaceable>, <replaceable class="PARAMETER">arg2</replaceable>, ...)|
28+
[ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <replaceable class="PARAMETER">object_name</replaceable> |
29+
COLUMN <replaceable class="PARAMETER">table_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
30+
AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> (<replaceable class="PARAMETER">agg_type</replaceable>) |
31+
FUNCTION <replaceable class="PARAMETER">func_name</replaceable> (<replaceable class="PARAMETER">arg1</replaceable>, <replaceable class="PARAMETER">arg2</replaceable>, ...) |
3332
OPERATOR <replaceable class="PARAMETER">op</replaceable> (<replaceable class="PARAMETER">leftoperand_type</replaceable> <replaceable class="PARAMETER">rightoperand_type</replaceable>) |
3433
TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable>
3534
] IS <replaceable class="PARAMETER">'text'</replaceable>
@@ -102,7 +101,7 @@ COMMENT
102101
<command>COMMENT</command> adds a comment to an object that can be
103102
easily retrieved with <command>psql</command>'s
104103
<command>\dd</command>, <command>\d+</command>, or <command>\l+</command> commands.
105-
To remove a comment,use <literal>NULL</literal>.
104+
To remove a comment,write <literal>NULL</literal>.
106105
Comments are automatically dropped when the object is dropped.
107106
</para>
108107
</refsect1>

‎doc/src/sgml/ref/drop_aggregate.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_aggregate.sgml,v 1.12 2001/09/0312:57:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_aggregate.sgml,v 1.13 2001/10/0320:54:20 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -23,7 +23,7 @@ Postgres documentation
2323
<date>1999-07-20</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
DROP AGGREGATE <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">type</replaceable>
26+
DROP AGGREGATE <replaceable class="PARAMETER">name</replaceable>(<replaceable class="PARAMETER">type</replaceable> )
2727
</synopsis>
2828

2929
<refsect2 id="R2-SQL-DROPAGGREGATE-1">
@@ -81,7 +81,7 @@ DROP
8181
</varlistentry>
8282
<varlistentry>
8383
<term><computeroutput>
84-
ERROR: RemoveAggregate: aggregate '<replaceable class="parameter">agg</replaceable>' for'<replaceable class="parameter">name</replaceable>' does not exist
84+
ERROR: RemoveAggregate: aggregate '<replaceable class="parameter">name</replaceable>' fortype<replaceable class="parameter">type</replaceable> does not exist
8585
</computeroutput></term>
8686
<listitem>
8787
<para>
@@ -133,7 +133,7 @@ ERROR: RemoveAggregate: aggregate '<replaceable class="parameter">agg</replaceab
133133
<literal>int4</literal>:
134134
</para>
135135
<programlisting>
136-
DROP AGGREGATE myavgint4;
136+
DROP AGGREGATE myavg(int4);
137137
</programlisting>
138138
</refsect1>
139139

‎src/backend/commands/comment.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1999-2001, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.32 2001/08/10 18:57:34 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.33 2001/10/03 20:54:20 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -25,6 +25,7 @@
2525
#include"catalog/pg_type.h"
2626
#include"commands/comment.h"
2727
#include"miscadmin.h"
28+
#include"parser/parse_agg.h"
2829
#include"parser/parse_expr.h"
2930
#include"parser/parse_func.h"
3031
#include"parser/parse.h"
@@ -568,7 +569,7 @@ static void
568569
CommentAggregate(char*aggregate,List*arguments,char*comment)
569570
{
570571
TypeName*aggtype= (TypeName*)lfirst(arguments);
571-
char*aggtypename=NULL;
572+
char*aggtypename;
572573
Oidbaseoid,
573574
oid;
574575
Oidclassoid;
@@ -590,12 +591,12 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
590591

591592
if (!pg_aggr_ownercheck(GetUserId(),aggregate,baseoid))
592593
{
593-
if (aggtypename)
594-
elog(ERROR,"you are not permitted to comment on aggregate '%s' with type '%s'",
595-
aggregate,aggtypename);
596-
else
597-
elog(ERROR,"you are not permitted to comment on aggregate '%s'",
594+
if (baseoid==InvalidOid)
595+
elog(ERROR,"you are not permitted to comment on aggregate '%s' for all types",
598596
aggregate);
597+
else
598+
elog(ERROR,"you are not permitted to comment on aggregate '%s' for type %s",
599+
aggregate,format_type_be(baseoid));
599600
}
600601

601602
/* Now, attempt to find the actual tuple in pg_aggregate */
@@ -605,13 +606,7 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
605606
ObjectIdGetDatum(baseoid),
606607
0,0);
607608
if (!OidIsValid(oid))
608-
{
609-
if (aggtypename)
610-
elog(ERROR,"aggregate type '%s' does not exist for aggregate '%s'",
611-
aggtypename,aggregate);
612-
else
613-
elog(ERROR,"aggregate '%s' does not exist",aggregate);
614-
}
609+
agg_error("CommentAggregate",aggregate,baseoid);
615610

616611
/* pg_aggregate doesn't have a hard-coded OID, so must look it up */
617612

‎src/backend/commands/remove.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.62 2001/08/10 18:57:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.63 2001/10/03 20:54:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,9 +22,11 @@
2222
#include"commands/comment.h"
2323
#include"commands/defrem.h"
2424
#include"miscadmin.h"
25+
#include"parser/parse_agg.h"
2526
#include"parser/parse_expr.h"
2627
#include"parser/parse_func.h"
2728
#include"utils/acl.h"
29+
#include"utils/builtins.h"
2830
#include"utils/syscache.h"
2931

3032

@@ -354,7 +356,7 @@ RemoveAggregate(char *aggName, char *aggType)
354356
{
355357
Relationrelation;
356358
HeapTupletup;
357-
OidbasetypeID=InvalidOid;
359+
OidbasetypeID;
358360
booldefined;
359361

360362
/*
@@ -363,8 +365,7 @@ RemoveAggregate(char *aggName, char *aggType)
363365
*
364366
* else if the basetype is blank, then attempt to find an aggregate with
365367
* a basetype of zero.This is valid. It means that the aggregate is
366-
* to apply to all basetypes. ie, a counter of some sort.
367-
*
368+
* to apply to all basetypes (eg, COUNT).
368369
*/
369370

370371
if (aggType)
@@ -374,20 +375,16 @@ RemoveAggregate(char *aggName, char *aggType)
374375
elog(ERROR,"RemoveAggregate: type '%s' does not exist",aggType);
375376
}
376377
else
377-
basetypeID=0;
378+
basetypeID=InvalidOid;
378379

379380
if (!pg_aggr_ownercheck(GetUserId(),aggName,basetypeID))
380381
{
381-
if (aggType)
382-
{
383-
elog(ERROR,"RemoveAggregate: aggregate '%s' on type '%s': permission denied",
384-
aggName,aggType);
385-
}
386-
else
387-
{
388-
elog(ERROR,"RemoveAggregate: aggregate '%s': permission denied",
382+
if (basetypeID==InvalidOid)
383+
elog(ERROR,"RemoveAggregate: aggregate '%s' for all types: permission denied",
389384
aggName);
390-
}
385+
else
386+
elog(ERROR,"RemoveAggregate: aggregate '%s' for type %s: permission denied",
387+
aggName,format_type_be(basetypeID));
391388
}
392389

393390
relation=heap_openr(AggregateRelationName,RowExclusiveLock);
@@ -398,19 +395,7 @@ RemoveAggregate(char *aggName, char *aggType)
398395
0,0);
399396

400397
if (!HeapTupleIsValid(tup))
401-
{
402-
heap_close(relation,RowExclusiveLock);
403-
if (aggType)
404-
{
405-
elog(ERROR,"RemoveAggregate: aggregate '%s' for '%s' does not exist",
406-
aggName,aggType);
407-
}
408-
else
409-
{
410-
elog(ERROR,"RemoveAggregate: aggregate '%s' for all types does not exist",
411-
aggName);
412-
}
413-
}
398+
agg_error("RemoveAggregate",aggName,basetypeID);
414399

415400
/* Remove any comments related to this aggregate */
416401
DeleteComments(tup->t_data->t_oid,RelationGetRelid(relation));

‎src/backend/parser/analyze.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.199 2001/10/0305:29:12 thomas Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.200 2001/10/0320:54:20 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -2811,8 +2811,10 @@ transformTypeRefsList(ParseState *pstate, List *l)
28112811

28122812
foreach(ele,l)
28132813
{
2814-
if (IsA(lfirst(ele),TypeName))
2815-
transformTypeRef(pstate, (TypeName*)lfirst(ele));
2814+
Node*elem=lfirst(ele);
2815+
2816+
if (elem&&IsA(elem,TypeName))
2817+
transformTypeRef(pstate, (TypeName*)elem);
28162818
}
28172819
}
28182820

‎src/backend/parser/gram.y

Lines changed: 34 additions & 31 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.257 2001/10/0305:29:12 thomas Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.258 2001/10/0320:54:21 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -217,8 +217,7 @@ static void doNegateFloat(Value *v);
217217
%type<boolean>opt_freeze,analyze_keyword
218218

219219
%type<ival>copy_dirn,direction,reindex_type,drop_type,
220-
opt_column,event,comment_type,comment_cl,
221-
comment_ag,comment_fn,comment_op,comment_tg
220+
opt_column,event,comment_type
222221

223222
%type<ival>fetch_how_many
224223

@@ -2011,7 +2010,7 @@ TruncateStmt: TRUNCATE opt_table relation_name
20112010
* the object associated with the comment. The form of the statement is:
20122011
*
20132012
* COMMENT ON [ [ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
2014-
* <objname> | AGGREGATE <aggname> <aggtype> | FUNCTION
2013+
* <objname> | AGGREGATE <aggname>(<aggtype>) | FUNCTION
20152014
* <funcname> (arg1, arg2, ...) | OPERATOR <op>
20162015
* (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON
20172016
* <relname> ] IS 'text'
@@ -2028,50 +2027,61 @@ CommentStmt:COMMENT ON comment_type name IS comment_text
20282027
n->comment =$6;
20292028
$$ = (Node *) n;
20302029
}
2031-
|COMMENTONcomment_clrelation_name'.'attr_nameIScomment_text
2030+
|COMMENTONCOLUMNrelation_name'.'attr_nameIScomment_text
20322031
{
20332032
CommentStmt *n = makeNode(CommentStmt);
2034-
n->objtype =$3;
2033+
n->objtype =COLUMN;
20352034
n->objname =$4;
20362035
n->objproperty =$6;
20372036
n->objlist =NULL;
20382037
n->comment =$8;
20392038
$$ = (Node *) n;
20402039
}
2041-
|COMMENTONcomment_agnameaggr_argtypeIScomment_text
2040+
|COMMENTONAGGREGATEname'('aggr_argtype')'IScomment_text
20422041
{
20432042
CommentStmt *n = makeNode(CommentStmt);
2044-
n->objtype =$3;
2043+
n->objtype = AGGREGATE;
2044+
n->objname =$4;
2045+
n->objproperty =NULL;
2046+
n->objlist = makeList1($6);
2047+
n->comment =$9;
2048+
$$ = (Node *) n;
2049+
}
2050+
|COMMENTONAGGREGATEnameaggr_argtypeIScomment_text
2051+
{
2052+
/* Obsolete syntax, but must support for awhile*/
2053+
CommentStmt *n = makeNode(CommentStmt);
2054+
n->objtype = AGGREGATE;
20452055
n->objname =$4;
20462056
n->objproperty =NULL;
20472057
n->objlist = makeList1($5);
20482058
n->comment =$7;
20492059
$$ = (Node *) n;
20502060
}
2051-
|COMMENTONcomment_fnfunc_namefunc_argsIScomment_text
2061+
|COMMENTONFUNCTIONfunc_namefunc_argsIScomment_text
20522062
{
20532063
CommentStmt *n = makeNode(CommentStmt);
2054-
n->objtype =$3;
2064+
n->objtype =FUNCTION;
20552065
n->objname =$4;
20562066
n->objproperty =NULL;
20572067
n->objlist =$5;
20582068
n->comment =$7;
20592069
$$ = (Node *) n;
20602070
}
2061-
|COMMENTONcomment_opall_Op'('oper_argtypes')'IScomment_text
2071+
|COMMENTONOPERATORall_Op'('oper_argtypes')'IScomment_text
20622072
{
20632073
CommentStmt *n = makeNode(CommentStmt);
2064-
n->objtype =$3;
2074+
n->objtype =OPERATOR;
20652075
n->objname =$4;
20662076
n->objproperty =NULL;
20672077
n->objlist =$6;
20682078
n->comment =$9;
20692079
$$ = (Node *) n;
20702080
}
2071-
|COMMENTONcomment_tgnameONrelation_nameIScomment_text
2081+
|COMMENTONTRIGGERnameONrelation_nameIScomment_text
20722082
{
20732083
CommentStmt *n = makeNode(CommentStmt);
2074-
n->objtype =$3;
2084+
n->objtype =TRIGGER;
20752085
n->objname =$4;
20762086
n->objproperty =$6;
20772087
n->objlist =NULL;
@@ -2089,21 +2099,6 @@ comment_type:DATABASE { $$ = DATABASE; }
20892099
|VIEW {$$ = VIEW; }
20902100
;
20912101

2092-
comment_cl:COLUMN {$$ = COLUMN; }
2093-
;
2094-
2095-
comment_ag:AGGREGATE {$$ = AGGREGATE; }
2096-
;
2097-
2098-
comment_fn:FUNCTION {$$ = FUNCTION; }
2099-
;
2100-
2101-
comment_op:OPERATOR {$$ = OPERATOR; }
2102-
;
2103-
2104-
comment_tg:TRIGGER {$$ = TRIGGER; }
2105-
;
2106-
21072102
comment_text:Sconst {$$ =$1; }
21082103
|NULL_P {$$ =NULL; }
21092104
;
@@ -2601,7 +2596,7 @@ func_type:Typename
26012596
*QUERY:
26022597
*
26032598
*DROP FUNCTION funcname (arg1, arg2, ...)
2604-
*DROP AGGREGATE aggname aggtype
2599+
*DROP AGGREGATE aggname(aggtype)
26052600
*DROP OPERATOR opname (leftoperand_typ rightoperand_typ)
26062601
*
26072602
*****************************************************************************/
@@ -2615,8 +2610,16 @@ RemoveFuncStmt: DROP FUNCTION func_name func_args
26152610
}
26162611
;
26172612

2618-
RemoveAggrStmt:DROPAGGREGATEfunc_nameaggr_argtype
2613+
RemoveAggrStmt:DROPAGGREGATEfunc_name'('aggr_argtype')'
2614+
{
2615+
RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
2616+
n->aggname =$3;
2617+
n->aggtype = (Node *)$5;
2618+
$$ = (Node *)n;
2619+
}
2620+
|DROPAGGREGATEfunc_nameaggr_argtype
26192621
{
2622+
/* Obsolete syntax, but must support for awhile*/
26202623
RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
26212624
n->aggname =$3;
26222625
n->aggtype = (Node *)$4;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp