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

Commite1e6069

Browse files
committed
Make CREATE AGGREGATE complain if the initcond is invalid for the datatype.
The initial transition value is stored as a text string and not fed to thetransition type's input function until runtime (so that values such as"now" don't get frozen at creation time). Previously, CREATE AGGREGATEdidn't do anything with it but that, which meant that even erroneous valueswould be accepted and not complained of until the aggregate is used. Thisseems unhelpful, and it's confused at least one user, as in Rhys Stewart'srecent report. It seems worth taking a few more cycles to invoke the inputfunction and verify that the value is acceptable. We can't do this if thetransition type is polymorphic, but in normal aggregates we know the actualtransition type so we can call the right input function.
1 parent7072635 commite1e6069

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

‎src/backend/commands/aggregatecmds.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
6161
Oid*aggArgTypes;
6262
intnumArgs;
6363
OidtransTypeId;
64+
chartransTypeType;
6465
ListCell*pl;
6566

6667
/* Convert list of names to a name and namespace */
@@ -181,7 +182,8 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
181182
* aggregate.
182183
*/
183184
transTypeId=typenameTypeId(NULL,transType);
184-
if (get_typtype(transTypeId)==TYPTYPE_PSEUDO&&
185+
transTypeType=get_typtype(transTypeId);
186+
if (transTypeType==TYPTYPE_PSEUDO&&
185187
!IsPolymorphicType(transTypeId))
186188
{
187189
if (transTypeId==INTERNALOID&&superuser())
@@ -193,6 +195,24 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
193195
format_type_be(transTypeId))));
194196
}
195197

198+
/*
199+
* If we have an initval, and it's not for a pseudotype (particularly a
200+
* polymorphic type), make sure it's acceptable to the type's input
201+
* function. We will store the initval as text, because the input
202+
* function isn't necessarily immutable (consider "now" for timestamp),
203+
* and we want to use the runtime not creation-time interpretation of the
204+
* value. However, if it's an incorrect value it seems much more
205+
* user-friendly to complain at CREATE AGGREGATE time.
206+
*/
207+
if (initval&&transTypeType!=TYPTYPE_PSEUDO)
208+
{
209+
Oidtypinput,
210+
typioparam;
211+
212+
getTypeInputInfo(transTypeId,&typinput,&typioparam);
213+
(void)OidInputFunctionCall(typinput,initval,typioparam,-1);
214+
}
215+
196216
/*
197217
* Most of the argument-checking is done inside of AggregateCreate
198218
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp