aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/aggregatecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-14 19:47:50 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-14 19:47:50 +0000
commit9e0247aba5e2cac1542823a194d4dc2ea1c3abb6 (patch)
tree5b5fb27746c965a5961ad16631788d113cfd6d11 /src/backend/commands/aggregatecmds.c
parentfbaa172d6553e0139ed98405eb4f24bf196f1394 (diff)
downloadpostgresql-9e0247aba5e2cac1542823a194d4dc2ea1c3abb6.tar.gz
postgresql-9e0247aba5e2cac1542823a194d4dc2ea1c3abb6.zip
In CREATE AGGREGATE, allow the transition datatype to be "internal", but only
if the user is superuser. This makes available to extension modules the same sort of trick being practiced by array_agg(). The reason for the superuser restriction is that you could crash the system by connecting up an incompatible pair of internal-using functions as an aggregate. It shouldn't interfere with any legitimate use, since you'd have to be superuser to create the internal-using transition and final functions anyway.
Diffstat (limited to 'src/backend/commands/aggregatecmds.c')
-rw-r--r--src/backend/commands/aggregatecmds.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c
index a8c9f1199e4..5bbb4bfdf74 100644
--- a/src/backend/commands/aggregatecmds.c
+++ b/src/backend/commands/aggregatecmds.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.46 2008/06/08 21:09:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.47 2008/11/14 19:47:50 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
@@ -173,15 +173,24 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
*
* transtype can't be a pseudo-type, since we need to be able to store
* values of the transtype. However, we can allow polymorphic transtype
- * in some cases (AggregateCreate will check).
+ * in some cases (AggregateCreate will check). Also, we allow "internal"
+ * for functions that want to pass pointers to private data structures;
+ * but allow that only to superusers, since you could crash the system
+ * (or worse) by connecting up incompatible internal-using functions
+ * in an aggregate.
*/
transTypeId = typenameTypeId(NULL, transType, NULL);
if (get_typtype(transTypeId) == TYPTYPE_PSEUDO &&
!IsPolymorphicType(transTypeId))
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
- errmsg("aggregate transition data type cannot be %s",
- format_type_be(transTypeId))));
+ {
+ if (transTypeId == INTERNALOID && superuser())
+ /* okay */ ;
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("aggregate transition data type cannot be %s",
+ format_type_be(transTypeId))));
+ }
/*
* Most of the argument-checking is done inside of AggregateCreate