diff options
Diffstat (limited to 'contrib/array')
-rw-r--r-- | contrib/array/Makefile | 11 | ||||
-rw-r--r-- | contrib/array/README.array_iterator | 49 | ||||
-rw-r--r-- | contrib/array/array_iterator.c | 372 | ||||
-rw-r--r-- | contrib/array/array_iterator.h | 45 | ||||
-rw-r--r-- | contrib/array/array_iterator.sql.in | 253 |
5 files changed, 0 insertions, 730 deletions
diff --git a/contrib/array/Makefile b/contrib/array/Makefile deleted file mode 100644 index 324fd2660a2..00000000000 --- a/contrib/array/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $Header: /cvsroot/pgsql/contrib/array/Attic/Makefile,v 1.16 2001/09/06 10:49:29 petere Exp $ - -subdir = contrib/array -top_builddir = ../.. -include $(top_builddir)/src/Makefile.global - -MODULES = array_iterator -DATA_built = array_iterator.sql -DOCS = README.array_iterator - -include $(top_srcdir)/contrib/contrib-global.mk diff --git a/contrib/array/README.array_iterator b/contrib/array/README.array_iterator deleted file mode 100644 index b072ebe3970..00000000000 --- a/contrib/array/README.array_iterator +++ /dev/null @@ -1,49 +0,0 @@ -Array iterator functions, by Massimo Dal Zotto <dz@cs.unitn.it> -Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it> - -This software is distributed under the GNU General Public License -either version 2, or (at your option) any later version. - - -This loadable module defines a new class of functions which take -an array and a scalar value, iterate a scalar operator over the -elements of the array and the value, and compute a result as -the logical OR or AND of the iteration results. -For example array_int4eq returns true if some of the elements -of an array of int4 is equal to the given value: - - array_int4eq({1,2,3}, 1) --> true - array_int4eq({1,2,3}, 4) --> false - -If we have defined T array types and O scalar operators we can -define T x O x 2 array functions, each of them has a name like -"array_[all_]<basetype><operation>" and takes an array of type T -iterating the operator O over all the elements. Note however -that some of the possible combination are invalid, for example -the array_int4_like because there is no like operator for int4. - -We can then define new operators based on these functions and use -them to write queries with qualification clauses based on the -values of some of the elements of an array. -For example to select rows having some or all element of an array -attribute equal to a given value or matching a regular expression: - - create table t(id int4[], txt text[]); - - -- select tuples with some id element equal to 123 - select * from t where t.id *= 123; - - -- select tuples with some txt element matching '[a-z]' - select * from t where t.txt *~ '[a-z]'; - - -- select tuples with all txt elements matching '^[A-Z]' - select * from t where t.txt[1:3] **~ '^[A-Z]'; - -The scheme is quite general, each operator which operates on a base type -can be iterated over the elements of an array. It seem to work well but -defining each new operators requires writing a different C function. -Furthermore in each function there are two hardcoded OIDs which reference -a base type and a procedure. Not very portable. Can anyone suggest a -better and more portable way to do it ? - -See also array_iterator.sql for an example on how to use this module. diff --git a/contrib/array/array_iterator.c b/contrib/array/array_iterator.c deleted file mode 100644 index 8a2455b673b..00000000000 --- a/contrib/array/array_iterator.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * array_iterator.c -- - * - * This file defines a new class of operators which take an - * array and a scalar value, iterate a scalar operator over the - * elements of the array and the value and compute a result as - * the logical OR or AND of the iteration results. - * - * Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it> - * ported to postgreSQL 6.3.2,added oid_functions, 18.1.1999, - * Tobias Gabele <gabele@wiz.uni-kassel.de> - * - * This software is distributed under the GNU General Public License - * either version 2, or (at your option) any later version. - */ - -#include "postgres.h" - -#include <ctype.h> -#include <stdio.h> -#include <sys/types.h> -#include <string.h> - -#include "access/tupmacs.h" -#include "access/xact.h" -#include "fmgr.h" -#include "miscadmin.h" -#include "utils/array.h" -#include "utils/builtins.h" -#include "utils/memutils.h" -#include "utils/lsyscache.h" - -#include "array_iterator.h" - - -static int32 -array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value) -{ - int16 typlen; - bool typbyval; - int nitems, - i; - Datum result; - int ndim, - *dim; - char *p; - FmgrInfo finfo; - - /* Sanity checks */ - if (array == (ArrayType *) NULL) - { - /* elog(WARNING, "array_iterator: array is null"); */ - return (0); - } - - /* detoast input if necessary */ - array = DatumGetArrayTypeP(PointerGetDatum(array)); - - ndim = ARR_NDIM(array); - dim = ARR_DIMS(array); - nitems = ArrayGetNItems(ndim, dim); - if (nitems == 0) - return (0); - - /* Lookup element type information */ - get_typlenbyval(elemtype, &typlen, &typbyval); - - /* Lookup the function entry point */ - fmgr_info(proc, &finfo); - if (finfo.fn_nargs != 2) - { - elog(ERROR, "array_iterator: proc %u does not take 2 args", proc); - return (0); - } - - /* Scan the array and apply the operator to each element */ - result = BoolGetDatum(false); - p = ARR_DATA_PTR(array); - for (i = 0; i < nitems; i++) - { - Datum itemvalue; - - itemvalue = fetch_att(p, typbyval, typlen); - - if (typlen > 0) - p += typlen; - else - p += INTALIGN(*(int32 *) p); - - result = FunctionCall2(&finfo, itemvalue, value); - - if (DatumGetBool(result)) - { - if (!and) - return (1); - } - else - { - if (and) - return (0); - } - } - - if (and && DatumGetBool(result)) - return (1); - else - return (0); -} - -/* - * Iterator functions for type _text - */ - -int32 -array_texteq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 25, /* text */ - (Oid) 67, /* texteq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_texteq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 25, /* text */ - (Oid) 67, /* texteq */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_textregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 25, /* text */ - (Oid) 1254, /* textregexeq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_textregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 25, /* text */ - (Oid) 1254, /* textregexeq */ - 1, /* logical and */ - array, (Datum) value); -} - -/* - * Iterator functions for type _varchar. Note that the regexp - * operators take the second argument of type text. - */ - -int32 -array_varchareq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1043, /* varchar */ - (Oid) 1070, /* varchareq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_varchareq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1043, /* varchar */ - (Oid) 1070, /* varchareq */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_varcharregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1043, /* varchar */ - (Oid) 1254, /* textregexeq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_varcharregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1043, /* varchar */ - (Oid) 1254, /* textregexeq */ - 1, /* logical and */ - array, (Datum) value); -} - -/* - * Iterator functions for type _bpchar. Note that the regexp - * operators take the second argument of type text. - */ - -int32 -array_bpchareq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1042, /* bpchar */ - (Oid) 1048, /* bpchareq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_bpchareq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1042, /* bpchar */ - (Oid) 1048, /* bpchareq */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_bpcharregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1042, /* bpchar */ - (Oid) 1254, /* textregexeq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_bpcharregexeq(ArrayType *array, char *value) -{ - return array_iterator((Oid) 1042, /* bpchar */ - (Oid) 1254, /* textregexeq */ - 1, /* logical and */ - array, (Datum) value); -} - -/* - * Iterator functions for type _int4 - */ - -int32 -array_int4eq(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 65, /* int4eq */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4eq(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 65, /* int4eq */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_int4ne(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 144, /* int4ne */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4ne(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 144, /* int4ne */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_int4gt(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 147, /* int4gt */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4gt(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 147, /* int4gt */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_int4ge(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 150, /* int4ge */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4ge(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 150, /* int4ge */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_int4lt(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 66, /* int4lt */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4lt(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 66, /* int4lt */ - 1, /* logical and */ - array, (Datum) value); -} - -int32 -array_int4le(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 149, /* int4le */ - 0, /* logical or */ - array, (Datum) value); -} - -int32 -array_all_int4le(ArrayType *array, int4 value) -{ - return array_iterator((Oid) 23, /* int4 */ - (Oid) 149, /* int4le */ - 1, /* logical and */ - array, (Datum) value); -} - -/* new tobias gabele 1999 */ - -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 */ - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/contrib/array/array_iterator.h b/contrib/array/array_iterator.h deleted file mode 100644 index 7889fdc0b2a..00000000000 --- a/contrib/array/array_iterator.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef ARRAY_ITERATOR_H -#define ARRAY_ITERATOR_H - -static int32 array_iterator(Oid elemtype, Oid proc, int and, - ArrayType *array, Datum value); - -int32 array_texteq(ArrayType *array, char *value); -int32 array_all_texteq(ArrayType *array, char *value); -int32 array_textregexeq(ArrayType *array, char *value); -int32 array_all_textregexeq(ArrayType *array, char *value); - -int32 array_varchareq(ArrayType *array, char *value); -int32 array_all_varchareq(ArrayType *array, char *value); -int32 array_varcharregexeq(ArrayType *array, char *value); -int32 array_all_varcharregexeq(ArrayType *array, char *value); - -int32 array_bpchareq(ArrayType *array, char *value); -int32 array_all_bpchareq(ArrayType *array, char *value); -int32 array_bpcharregexeq(ArrayType *array, char *value); -int32 array_all_bpcharregexeq(ArrayType *array, char *value); - -int32 array_int4eq(ArrayType *array, int4 value); -int32 array_all_int4eq(ArrayType *array, int4 value); -int32 array_int4ne(ArrayType *array, int4 value); -int32 array_all_int4ne(ArrayType *array, int4 value); -int32 array_int4gt(ArrayType *array, int4 value); -int32 array_all_int4gt(ArrayType *array, int4 value); -int32 array_int4ge(ArrayType *array, int4 value); -int32 array_all_int4ge(ArrayType *array, int4 value); -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 - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/contrib/array/array_iterator.sql.in b/contrib/array/array_iterator.sql.in deleted file mode 100644 index d4182b112e2..00000000000 --- a/contrib/array/array_iterator.sql.in +++ /dev/null @@ -1,253 +0,0 @@ --- SQL code to define the new array iterator functions and operators - --- define the array operators *=, **=, *~ and **~ for type _text --- -create function array_texteq(_text, text) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_texteq(_text, text) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_textregexeq(_text, text) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_textregexeq(_text, text) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create operator *= ( - leftarg=_text, - rightarg=text, - procedure=array_texteq); - -create operator **= ( - leftarg=_text, - rightarg=text, - procedure=array_all_texteq); - -create operator *~ ( - leftarg=_text, - rightarg=text, - procedure=array_textregexeq); - -create operator **~ ( - leftarg=_text, - rightarg=text, - procedure=array_all_textregexeq); - - --- define the array operators *=, **=, *~ and **~ for type _varchar --- --- NOTE: "varchar" is also a reserved word and must be quoted. --- -create function array_varchareq(_varchar, varchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_varchareq(_varchar, varchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_varcharregexeq(_varchar, varchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_varcharregexeq(_varchar, varchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create operator *= ( - leftarg=_varchar, - rightarg="varchar", - procedure=array_varchareq); - -create operator **= ( - leftarg=_varchar, - rightarg="varchar", - procedure=array_all_varchareq); - -create operator *~ ( - leftarg=_varchar, - rightarg="varchar", - procedure=array_varcharregexeq); - -create operator **~ ( - leftarg=_varchar, - rightarg="varchar", - procedure=array_all_varcharregexeq); - - --- define the array operators *=, **=, *~ and **~ for type _bpchar --- -create function array_bpchareq(_bpchar, bpchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_bpchareq(_bpchar, bpchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_bpcharregexeq(_bpchar, bpchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_bpcharregexeq(_bpchar, bpchar) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create operator *= ( - leftarg=_bpchar, - rightarg=bpchar, - procedure=array_bpchareq); - -create operator **= ( - leftarg=_bpchar, - rightarg=bpchar, - procedure=array_all_bpchareq); - -create operator *~ ( - leftarg=_bpchar, - rightarg=bpchar, - procedure=array_bpcharregexeq); - -create operator **~ ( - leftarg=_bpchar, - rightarg=bpchar, - procedure=array_all_bpcharregexeq); - - --- define the array operators *=, **=, *> and **> for type _int4 --- -create function array_int4eq(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4eq(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_int4ne(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4ne(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_int4gt(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4gt(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_int4ge(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4ge(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_int4lt(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4lt(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_int4le(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create function array_all_int4le(_int4, int4) returns bool - as 'MODULE_PATHNAME' - language 'c'; - -create operator *= ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4eq); - -create operator **= ( - leftarg=_int4, - rightarg=int4, - procedure=array_all_int4eq); - -create operator *<> ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4ne); - -create operator **<> ( - leftarg=_int4, - rightarg=int4, - procedure=array_all_int4ne); - -create operator *> ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4gt); - -create operator **> ( - leftarg=_int4, - rightarg=int4, - procedure=array_all_int4gt); - -create operator *>= ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4ge); - -create operator **>= ( - leftarg=_int4, - rightarg=int4, - procedure=array_all_int4ge); - -create operator *< ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4lt); - -create operator **< ( - leftarg=_int4, - rightarg=int4, - procedure=array_all_int4lt); - -create operator *<= ( - leftarg=_int4, - rightarg=int4, - procedure=array_int4le); - -create operator **<= ( - leftarg=_int4, - 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 |