]> granicus.if.org Git - postgresql/blobdiff - src/backend/catalog/pg_aggregate.c
Change #include's to use <> and "" as appropriate.
[postgresql] / src / backend / catalog / pg_aggregate.c
index 4c3b11c54c6b0fbc83fce7e1b1414afb9b20c2fd..7a118888132b1ef0c488dd70a30422bf80f626e1 100644 (file)
@@ -1,30 +1,27 @@
 /*-------------------------------------------------------------------------
  *
- * pg_aggregate.c--
+ * pg_aggregate.c
  *       routines to support manipulation of the pg_aggregate relation
  *
  * Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.9 1997/09/18 20:20:15 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.22 1999/07/15 23:03:04 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
-#include <postgres.h>
+#include "postgres.h"
 
-#include <access/heapam.h>
-#include <utils/builtins.h>
-#include <fmgr.h>
-#include <catalog/catname.h>
-#include <utils/syscache.h>
-#include <catalog/pg_operator.h>
-#include <catalog/pg_proc.h>
-#include <catalog/pg_type.h>
-#include <catalog/pg_aggregate.h>
-#include <miscadmin.h>
+#include "access/heapam.h"
+#include "utils/builtins.h"
+#include "catalog/catname.h"
+#include "utils/syscache.h"
+#include "catalog/pg_proc.h"
+#include "catalog/pg_type.h"
+#include "catalog/pg_aggregate.h"
+#include "miscadmin.h"
 #ifndef HAVE_MEMMOVE
-#include <regex/utils.h>
 #else
 #include <string.h>
 #endif
@@ -64,7 +61,7 @@ AggregateCreate(char *aggName,
                                char *agginitval1,
                                char *agginitval2)
 {
-       register        i;
+       int                     i;
        Relation        aggdesc;
        HeapTuple       tup;
        char            nulls[Natts_pg_aggregate];
@@ -78,23 +75,24 @@ AggregateCreate(char *aggName,
        Oid                     xret2 = InvalidOid;
        Oid                     fret = InvalidOid;
        Oid                     fnArgs[8];
+       NameData        aname;
        TupleDesc       tupDesc;
 
        MemSet(fnArgs, 0, 8 * sizeof(Oid));
 
        /* sanity checks */
        if (!aggName)
-               elog(WARN, "AggregateCreate: no aggregate name supplied");
+               elog(ERROR, "AggregateCreate: no aggregate name supplied");
 
        if (!aggtransfn1Name && !aggtransfn2Name)
-               elog(WARN, "AggregateCreate: aggregate must have at least one transition function");
+               elog(ERROR, "AggregateCreate: aggregate must have at least one transition function");
 
        tup = SearchSysCacheTuple(TYPNAME,
                                                          PointerGetDatum(aggbasetypeName),
                                                          0, 0, 0);
        if (!HeapTupleIsValid(tup))
-               elog(WARN, "AggregateCreate: Type '%s' undefined", aggbasetypeName);
-       xbase = tup->t_oid;
+               elog(ERROR, "AggregateCreate: Type '%s' undefined", aggbasetypeName);
+       xbase = tup->t_data->t_oid;
 
        if (aggtransfn1Name)
        {
@@ -102,9 +100,9 @@ AggregateCreate(char *aggName,
                                                                  PointerGetDatum(aggtransfn1typeName),
                                                                  0, 0, 0);
                if (!HeapTupleIsValid(tup))
-                       elog(WARN, "AggregateCreate: Type '%s' undefined",
+                       elog(ERROR, "AggregateCreate: Type '%s' undefined",
                                 aggtransfn1typeName);
-               xret1 = tup->t_oid;
+               xret1 = tup->t_data->t_oid;
 
                fnArgs[0] = xret1;
                fnArgs[1] = xbase;
@@ -114,16 +112,16 @@ AggregateCreate(char *aggName,
                                                                  PointerGetDatum(fnArgs),
                                                                  0);
                if (!HeapTupleIsValid(tup))
-                       elog(WARN, "AggregateCreate: '%s('%s', '%s') does not exist",
+                       elog(ERROR, "AggregateCreate: '%s('%s', '%s') does not exist",
                                 aggtransfn1Name, aggtransfn1typeName, aggbasetypeName);
                if (((Form_pg_proc) GETSTRUCT(tup))->prorettype != xret1)
-                       elog(WARN, "AggregateCreate: return type of '%s' is not '%s'",
+                       elog(ERROR, "AggregateCreate: return type of '%s' is not '%s'",
                                 aggtransfn1Name,
                                 aggtransfn1typeName);
-               xfn1 = tup->t_oid;
+               xfn1 = tup->t_data->t_oid;
                if (!OidIsValid(xfn1) || !OidIsValid(xret1) ||
                        !OidIsValid(xbase))
-                       elog(WARN, "AggregateCreate: bogus function '%s'", aggfinalfnName);
+                       elog(ERROR, "AggregateCreate: bogus function '%s'", aggfinalfnName);
        }
 
        if (aggtransfn2Name)
@@ -132,9 +130,9 @@ AggregateCreate(char *aggName,
                                                                  PointerGetDatum(aggtransfn2typeName),
                                                                  0, 0, 0);
                if (!HeapTupleIsValid(tup))
-                       elog(WARN, "AggregateCreate: Type '%s' undefined",
+                       elog(ERROR, "AggregateCreate: Type '%s' undefined",
                                 aggtransfn2typeName);
-               xret2 = tup->t_oid;
+               xret2 = tup->t_data->t_oid;
 
                fnArgs[0] = xret2;
                fnArgs[1] = 0;
@@ -144,30 +142,31 @@ AggregateCreate(char *aggName,
                                                                  PointerGetDatum(fnArgs),
                                                                  0);
                if (!HeapTupleIsValid(tup))
-                       elog(WARN, "AggregateCreate: '%s'('%s') does not exist",
+                       elog(ERROR, "AggregateCreate: '%s'('%s') does not exist",
                                 aggtransfn2Name, aggtransfn2typeName);
                if (((Form_pg_proc) GETSTRUCT(tup))->prorettype != xret2)
-                       elog(WARN, "AggregateCreate: return type of '%s' is not '%s'",
+                       elog(ERROR, "AggregateCreate: return type of '%s' is not '%s'",
                                 aggtransfn2Name, aggtransfn2typeName);
-               xfn2 = tup->t_oid;
+               xfn2 = tup->t_data->t_oid;
                if (!OidIsValid(xfn2) || !OidIsValid(xret2))
-                       elog(WARN, "AggregateCreate: bogus function '%s'", aggfinalfnName);
+                       elog(ERROR, "AggregateCreate: bogus function '%s'", aggfinalfnName);
        }
 
-       tup = SearchSysCacheTuple(AGGNAME, PointerGetDatum(aggName),
+       tup = SearchSysCacheTuple(AGGNAME,
+                                                         PointerGetDatum(aggName),
                                                          ObjectIdGetDatum(xbase),
                                                          0, 0);
        if (HeapTupleIsValid(tup))
-               elog(WARN,
+               elog(ERROR,
                         "AggregateCreate: aggregate '%s' with base type '%s' already exists",
                         aggName, aggbasetypeName);
 
        /* more sanity checks */
        if (aggtransfn1Name && aggtransfn2Name && !aggfinalfnName)
-               elog(WARN, "AggregateCreate: Aggregate must have final function with both transition functions");
+               elog(ERROR, "AggregateCreate: Aggregate must have final function with both transition functions");
 
        if ((!aggtransfn1Name || !aggtransfn2Name) && aggfinalfnName)
-               elog(WARN, "AggregateCreate: Aggregate cannot have final function without both transition functions");
+               elog(ERROR, "AggregateCreate: Aggregate cannot have final function without both transition functions");
 
        if (aggfinalfnName)
        {
@@ -179,13 +178,13 @@ AggregateCreate(char *aggName,
                                                                  PointerGetDatum(fnArgs),
                                                                  0);
                if (!HeapTupleIsValid(tup))
-                       elog(WARN, "AggregateCreate: '%s'('%s','%s') does not exist",
+                       elog(ERROR, "AggregateCreate: '%s'('%s','%s') does not exist",
                           aggfinalfnName, aggtransfn1typeName, aggtransfn2typeName);
-               ffn = tup->t_oid;
+               ffn = tup->t_data->t_oid;
                proc = (Form_pg_proc) GETSTRUCT(tup);
                fret = proc->prorettype;
                if (!OidIsValid(ffn) || !OidIsValid(fret))
-                       elog(WARN, "AggregateCreate: bogus function '%s'", aggfinalfnName);
+                       elog(ERROR, "AggregateCreate: bogus function '%s'", aggfinalfnName);
        }
 
        /*
@@ -194,7 +193,7 @@ AggregateCreate(char *aggName,
         * aggregates to return NULL if they are evaluated on empty sets.
         */
        if (OidIsValid(xfn2) && !agginitval2)
-               elog(WARN, "AggregateCreate: transition function 2 MUST have an initial value");
+               elog(ERROR, "AggregateCreate: transition function 2 MUST have an initial value");
 
        /* initialize nulls and values */
        for (i = 0; i < Natts_pg_aggregate; i++)
@@ -202,44 +201,31 @@ AggregateCreate(char *aggName,
                nulls[i] = ' ';
                values[i] = (Datum) NULL;
        }
-       values[Anum_pg_aggregate_aggname - 1] = PointerGetDatum(aggName);
-       values[Anum_pg_aggregate_aggowner - 1] =
-               Int32GetDatum(GetUserId());
-       values[Anum_pg_aggregate_aggtransfn1 - 1] =
-               ObjectIdGetDatum(xfn1);
-       values[Anum_pg_aggregate_aggtransfn2 - 1] =
-               ObjectIdGetDatum(xfn2);
-       values[Anum_pg_aggregate_aggfinalfn - 1] =
-               ObjectIdGetDatum(ffn);
+       namestrcpy(&aname, aggName);
+       values[Anum_pg_aggregate_aggname - 1] = NameGetDatum(&aname);
+       values[Anum_pg_aggregate_aggowner - 1] = Int32GetDatum(GetUserId());
+       values[Anum_pg_aggregate_aggtransfn1 - 1] = ObjectIdGetDatum(xfn1);
+       values[Anum_pg_aggregate_aggtransfn2 - 1] = ObjectIdGetDatum(xfn2);
+       values[Anum_pg_aggregate_aggfinalfn - 1] = ObjectIdGetDatum(ffn);
 
-       values[Anum_pg_aggregate_aggbasetype - 1] =
-               ObjectIdGetDatum(xbase);
+       values[Anum_pg_aggregate_aggbasetype - 1] = ObjectIdGetDatum(xbase);
        if (!OidIsValid(xfn1))
        {
-               values[Anum_pg_aggregate_aggtranstype1 - 1] =
-                       ObjectIdGetDatum(InvalidOid);
-               values[Anum_pg_aggregate_aggtranstype2 - 1] =
-                       ObjectIdGetDatum(xret2);
-               values[Anum_pg_aggregate_aggfinaltype - 1] =
-                       ObjectIdGetDatum(xret2);
+               values[Anum_pg_aggregate_aggtranstype1 - 1] = ObjectIdGetDatum(InvalidOid);
+               values[Anum_pg_aggregate_aggtranstype2 - 1] = ObjectIdGetDatum(xret2);
+               values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(xret2);
        }
        else if (!OidIsValid(xfn2))
        {
-               values[Anum_pg_aggregate_aggtranstype1 - 1] =
-                       ObjectIdGetDatum(xret1);
-               values[Anum_pg_aggregate_aggtranstype2 - 1] =
-                       ObjectIdGetDatum(InvalidOid);
-               values[Anum_pg_aggregate_aggfinaltype - 1] =
-                       ObjectIdGetDatum(xret1);
+               values[Anum_pg_aggregate_aggtranstype1 - 1] = ObjectIdGetDatum(xret1);
+               values[Anum_pg_aggregate_aggtranstype2 - 1] = ObjectIdGetDatum(InvalidOid);
+               values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(xret1);
        }
        else
        {
-               values[Anum_pg_aggregate_aggtranstype1 - 1] =
-                       ObjectIdGetDatum(xret1);
-               values[Anum_pg_aggregate_aggtranstype2 - 1] =
-                       ObjectIdGetDatum(xret2);
-               values[Anum_pg_aggregate_aggfinaltype - 1] =
-                       ObjectIdGetDatum(fret);
+               values[Anum_pg_aggregate_aggtranstype1 - 1] = ObjectIdGetDatum(xret1);
+               values[Anum_pg_aggregate_aggtranstype2 - 1] = ObjectIdGetDatum(xret2);
+               values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(fret);
        }
 
        if (agginitval1)
@@ -253,21 +239,21 @@ AggregateCreate(char *aggName,
                nulls[Anum_pg_aggregate_agginitval2 - 1] = 'n';
 
        if (!RelationIsValid(aggdesc = heap_openr(AggregateRelationName)))
-               elog(WARN, "AggregateCreate: could not open '%s'",
+               elog(ERROR, "AggregateCreate: could not open '%s'",
                         AggregateRelationName);
 
        tupDesc = aggdesc->rd_att;
        if (!HeapTupleIsValid(tup = heap_formtuple(tupDesc,
                                                                                           values,
                                                                                           nulls)))
-               elog(WARN, "AggregateCreate: heap_formtuple failed");
+               elog(ERROR, "AggregateCreate: heap_formtuple failed");
        if (!OidIsValid(heap_insert(aggdesc, tup)))
-               elog(WARN, "AggregateCreate: heap_insert failed");
+               elog(ERROR, "AggregateCreate: heap_insert failed");
        heap_close(aggdesc);
 
 }
 
-char      *
+char *
 AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
 {
        HeapTuple       tup;
@@ -284,10 +270,10 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
 
        tup = SearchSysCacheTuple(AGGNAME,
                                                          PointerGetDatum(aggName),
-                                                         PointerGetDatum(basetype),
+                                                         ObjectIdGetDatum(basetype),
                                                          0, 0);
        if (!HeapTupleIsValid(tup))
-               elog(WARN, "AggNameGetInitVal: cache lookup failed for aggregate '%s'",
+               elog(ERROR, "AggNameGetInitVal: cache lookup failed for aggregate '%s'",
                         aggName);
        if (xfuncno == 1)
        {
@@ -303,7 +289,7 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
 
        aggRel = heap_openr(AggregateRelationName);
        if (!RelationIsValid(aggRel))
-               elog(WARN, "AggNameGetInitVal: could not open \"%-.*s\"",
+               elog(ERROR, "AggNameGetInitVal: could not open \"%-.*s\"",
                         AggregateRelationName);
 
        /*
@@ -311,26 +297,27 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
         * NULL
         */
        textInitVal = (text *) fastgetattr(tup, initValAttno,
-                                                                          RelationGetTupleDescriptor(aggRel),
+                                                                          RelationGetDescr(aggRel),
                                                                           isNull);
        if (!PointerIsValid(textInitVal))
                *isNull = true;
        if (*isNull)
        {
                heap_close(aggRel);
-               return ((char *) NULL);
+               return (char *) NULL;
        }
        strInitVal = textout(textInitVal);
        heap_close(aggRel);
 
-       tup = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(transtype),
+       tup = SearchSysCacheTuple(TYPOID,
+                                                         ObjectIdGetDatum(transtype),
                                                          0, 0, 0);
        if (!HeapTupleIsValid(tup))
        {
                pfree(strInitVal);
-               elog(WARN, "AggNameGetInitVal: cache lookup failed on aggregate transition function return type");
+               elog(ERROR, "AggNameGetInitVal: cache lookup failed on aggregate transition function return type");
        }
-       initVal = fmgr(((TypeTupleForm) GETSTRUCT(tup))->typinput, strInitVal, -1);
+       initVal = fmgr(((Form_pg_type) GETSTRUCT(tup))->typinput, strInitVal, -1);
        pfree(strInitVal);
-       return (initVal);
+       return initVal;
 }