i have made minor changes to array_iterator to make it work with
authorBruce Momjian
Thu, 21 Jan 1999 22:40:16 +0000 (22:40 +0000)
committerBruce Momjian
Thu, 21 Jan 1999 22:40:16 +0000 (22:40 +0000)
pgsql-6.3.2. I think array_iterator is a great thing to have!!!

With best regards,

Tobias Gabele

contrib/array/array_iterator.c
contrib/array/array_iterator.h
contrib/array/array_iterator.sql.in

index 06028ff4c6db127bd174c394452f0909c8d00a7d..fcf243e10033f3fa5ee43fe7a64603878bdafbe8 100644 (file)
@@ -6,10 +6,9 @@
  * elements of the array and the value and compute a result as
  * the logical OR or AND of the iteration results.
  *
- * Copyright (c) 1998, Massimo Dal Zotto 
- *
- * This file is distributed under the GNU General Public License
- * either version 2, or (at your option) any later version.
+ * Copyright (c) 1997, Massimo Dal Zotto 
+ * ported to postgreSQL 6.3.2,added oid_functions, 18.1.1999,
+ * Tobias Gabele 
  */
 
 #include 
@@ -20,7 +19,7 @@
 #include "postgres.h"
 #include "miscadmin.h"
 #include "access/xact.h"
-#include "backend/fmgr.h"
+#include "fmgr.h"
 #include "catalog/pg_type.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
 
 #include "array_iterator.h"
 
-static int32
 array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
 {
    HeapTuple   typ_tuple;
    TypeTupleForm typ_struct;
    bool        typbyval;
    int         typlen;
-   FmgrInfo    finfo;
+   func_ptr    proc_fn;
+   int         pronargs;
    int         nitems,
                i,
                result;
    int         ndim,
               *dim;
    char       *p;
+   FmgrInfo finf;    /*Tobias Gabele Jan 18 1999*/
 
    /* Sanity checks */
    if ((array == (ArrayType *) NULL)
@@ -72,8 +72,11 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
    typbyval = typ_struct->typbyval;
 
    /* Lookup the function entry point */
-   fmgr_info(proc, &finfo);
-   if ((finfo.fn_oid == 0) || (finfo.fn_nargs != 2))
+   proc_fn = (func_ptr) NULL;
+        fmgr_info(proc,&finf); /*Tobias Gabele Jan 18 1999*/
+        proc_fn=finf.fn_addr;  /*Tobias Gabele Jan 18 1999*/
+        pronargs=finf.fn_nargs; /*Tobias Gabele Jan 18 1999*/
+   if ((proc_fn == NULL) || (pronargs != 2))
    {
        elog(ERROR, "array_iterator: fmgr_info lookup failed for oid %d", proc);
        return (0);
@@ -89,42 +92,54 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
            switch (typlen)
            {
                case 1:
-                   result = (int) (*(finfo.fn_addr)) (*p, value);
+                   result = (int) (*proc_fn) (*p, value);
                    break;
                case 2:
-                   result = (int) (*(finfo.fn_addr)) (*(int16 *) p, value);
+                   result = (int) (*proc_fn) (*(int16 *) p, value);
                    break;
                case 3:
                case 4:
-                   result = (int) (*(finfo.fn_addr)) (*(int32 *) p, value);
+                   result = (int) (*proc_fn) (*(int32 *) p, value);
                    break;
            }
            p += typlen;
        }
        else
        {
-           result = (int) (*(finfo.fn_addr)) (p, value);
+           result = (int) (*proc_fn) (p, value);
            if (typlen > 0)
+           {
                p += typlen;
+           }
            else
+           {
                p += INTALIGN(*(int32 *) p);
+           }
        }
        if (result)
        {
            if (!and)
+           {
                return (1);
+           }
        }
        else
        {
            if (and)
+           {
                return (0);
+           }
        }
    }
 
    if (and && result)
+   {
        return (1);
+   }
    else
+   {
        return (0);
+   }
 }
 
 /*
@@ -167,6 +182,47 @@ array_all_textregexeq(ArrayType *array, char *value)
                          array, (Datum) value);
 }
 
+/*
+ * Iterator functions for type _char16. Note that the regexp
+ * operators take the second argument of type text.
+ */
+
+int32
+array_char16eq(ArrayType *array, char *value)
+{
+   return array_iterator((Oid) 20,     /* char16 */
+                         (Oid) 1275,   /* char16eq */
+                         0,    /* logical or */
+                         array, (Datum) value);
+}
+
+int32
+array_all_char16eq(ArrayType *array, char *value)
+{
+   return array_iterator((Oid) 20,     /* char16 */
+                         (Oid) 1275,   /* char16eq */
+                         1,    /* logical and */
+                         array, (Datum) value);
+}
+
+int32
+array_char16regexeq(ArrayType *array, char *value)
+{
+   return array_iterator((Oid) 20,     /* char16 */
+                         (Oid) 1288,   /* char16regexeq */
+                         0,    /* logical or */
+                         array, (Datum) value);
+}
+
+int32
+array_all_char16regexeq(ArrayType *array, char *value)
+{
+   return array_iterator((Oid) 20,     /* char16 */
+                         (Oid) 1288,   /* char16regexeq */
+                         1,    /* logical and */
+                         array, (Datum) value);
+}
+
 /*
  * Iterator functions for type _int4
  */
@@ -279,12 +335,31 @@ array_all_int4le(ArrayType *array, int4 value)
                          array, (Datum) value);
 }
 
-/* end of file */
+/* new tobias gabele 1999 */
 
-/*
- * Local variables:
- *  tab-width: 4
- *  c-indent-level: 4
- *  c-basic-offset: 4
- * End:
- */
+
+int32
+array_oideq(ArrayType *array, Oid value)
+{
+   return array_iterator((Oid) 26,     /* oid */
+                         (Oid) 184,        /* oideq */
+                         0,    /* logical or */
+                         array, (Datum) value);
+}
+
+int32
+array_all_oidne(ArrayType *array, Oid value)
+{
+   return array_iterator((Oid) 26,     /* int4 */
+                         (Oid) 185,    /* oidne */
+                         1,    /* logical and */
+                         array, (Datum) value);
+}
+
+
+
+
+
+
+
+/* end of file */
index 458ec5916d8d7b023e04ca39a53c0fb55a33c806..5eab8d985b384a3769d07057c77c250ed311ffe0 100644 (file)
@@ -24,5 +24,6 @@ int32     array_int4lt(ArrayType *array, int4 value);
 int32      array_all_int4lt(ArrayType *array, int4 value);
 int32      array_int4le(ArrayType *array, int4 value);
 int32      array_all_int4le(ArrayType *array, int4 value);
-
+int32           array_oideq(ArrayType *array, Oid value);
+int32           array_all_oidne(ArrayType *array, Oid value);
 #endif
index 40deb7e0c607a02c9ecfbd1febe5bf887117c2dc..cc95c8aea7b67ecb97d3ae2d9622a478f0e8895b 100644 (file)
@@ -1,13 +1,6 @@
--- array_iterator.sql --
---
--- SQL code to define the array iterator functions and operators.
---
--- Copyright (c) 1998, Massimo Dal Zotto 
---
--- This file is distributed under the GNU General Public License
--- either version 2, or (at your option) any later version.
+-- SQL code to define the new array iterator functions and operators
 
--- Define the array functions *=, **=, *~ and **~ for type _text
+-- define the array operators *=, **=, *~ and **~ for type _text
 --
 create function array_texteq(_text, text) returns bool
   as 'MODULE_PATHNAME' 
@@ -45,7 +38,47 @@ create operator **~ (
   rightarg=text,
   procedure=array_all_textregexeq);
 
--- Define the array functions *=, **=, *> and **> for type _int4
+
+-- define the array operators *=, **=, *~ and **~ for type _char16
+--
+create function array_char16eq(_char16, char16) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_all_char16eq(_char16, char16) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_char16regexeq(_char16, text) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_all_char16regexeq(_char16, text) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create operator *= (
+  leftarg=_char16,
+  rightarg=char16,
+  procedure=array_char16eq);
+
+create operator **= (
+  leftarg=_char16,
+  rightarg=char16,
+  procedure=array_all_char16eq);
+
+create operator *~ (
+  leftarg=_char16,
+  rightarg=text,
+  procedure=array_char16regexeq);
+
+create operator **~ (
+  leftarg=_char16,
+  rightarg=text,
+  procedure=array_all_char16regexeq);
+
+
+-- define the array operators *=, **=, *> and **> for type _int4
 --
 create function array_int4eq(_int4, int4) returns bool
   as 'MODULE_PATHNAME' 
@@ -95,8 +128,6 @@ create function array_all_int4le(_int4, int4) returns bool
   as 'MODULE_PATHNAME' 
   language 'c';
 
--- Define the operators corresponding to the above functions
---
 create operator *= (
   leftarg=_int4,
   rightarg=int4,
@@ -157,4 +188,26 @@ create operator **<= (
   rightarg=int4,
   procedure=array_all_int4le);
 
+-- define the array operators *=, **<>  for type _oid  (added tobias 1. 1999)
+--
+create function array_oideq(_oid, oid) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_all_oidne(_oid, oid) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create operator *= (
+  leftarg=_oid, 
+  rightarg=oid, 
+  procedure=array_oideq);
+
+create operator **<> (
+  leftarg=_oid,
+  rightarg=oid,
+  procedure=array_all_oidne);
+
+
+
 -- end of file