diff options
author | Bruce Momjian | 2000-06-15 18:55:34 +0000 |
---|---|---|
committer | Bruce Momjian | 2000-06-15 18:55:34 +0000 |
commit | f7f177d372750e4f766ccefdf20e1b30d66cba0a (patch) | |
tree | d4e2a148640ba36d9a1e8cbf8557faa606ce5ba1 /contrib/array | |
parent | 82c4733116813ff862dade1984b6fb74149f4124 (diff) |
/contrib patch from Karel.
Diffstat (limited to 'contrib/array')
-rw-r--r-- | contrib/array/Makefile | 74 | ||||
-rw-r--r-- | contrib/array/README | 49 |
2 files changed, 80 insertions, 43 deletions
diff --git a/contrib/array/Makefile b/contrib/array/Makefile index c29569d76f..04d785da72 100644 --- a/contrib/array/Makefile +++ b/contrib/array/Makefile @@ -1,65 +1,53 @@ -#------------------------------------------------------------------------- # -# Makefile -- +# $Header: /cvsroot/pgsql/contrib/array/Attic/Makefile,v 1.8 2000/06/15 18:54:31 momjian Exp $ # -# Makefile for array iterator module. -# -#------------------------------------------------------------------------- - -PGDIR = ../.. -SRCDIR = $(PGDIR)/src - -include $(SRCDIR)/Makefile.global - -CFLAGS += -I. $(CFLAGS_SL) -MODNAME = array_iterator +TOPDIR=../.. -SQLDEFS = $(MODNAME).sql +include ../Makefile.global -MODULE = $(MODNAME)$(DLSUFFIX) +NAME = array_iterator -MODDIR = $(LIBDIR)/modules +PROGRAM = +OBJS = $(NAME).o +DOCS = $(NAME).doc +SQLS = $(NAME).sql +BINS = +EXAMPLES= +MODS = $(NAME)$(DLSUFFIX) -SQLDIR = $(LIBDIR)/sql - -all: module sql - -module: $(MODULE) +CFLAGS += -I. $(CFLAGS_SL) -sql: $(SQLDEFS) +OTHER_CLEAN = $(SQLS) -install: $(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR) - cp -p $(MODULE) $(MODDIR)/ - strip $(MODDIR)/$(MODULE) - cp -p $(SQLDEFS) $(SQLDIR)/ +all: $(MODS) $(SQLS) -install-doc: - if [ -d "$(DOCDIR)" ]; then \ - cp -p *.doc $(DOCDIR); \ - else \ - cp -p *.doc $(SQLDIR); \ - fi +%.sql: %.sql.in + $(SED) "s|MODULE_PATHNAME|$(CONTRIB_MODDIR)/$@|" < $< > $@ -$(MODDIR): - mkdir -p $@ +install: install_doc install_sql install_mod -$(SQLDIR): - mkdir -p $@ +install_doc: + for inst_file in $(DOCS); do \ + $(INSTALL) $(INSTL_LIB_OPTS) $$inst_file $(CONTRIB_DOCDIR); \ + done -%.sql: %.sql.in - sed "s|MODULE_PATHNAME|$(MODDIR)/$(MODULE)|" < $< > $@ +install_sql: + for inst_file in $(SQLS); do \ + $(INSTALL) $(INSTL_LIB_OPTS) $$inst_file $(CONTRIB_SQLDIR); \ + done -.SUFFIXES: $(DLSUFFIX) +install_mod: + for inst_file in $(MODS); do \ + $(INSTALL) $(INSTL_SHLIB_OPTS) $$inst_file $(CONTRIB_MODDIR); \ + done -%$(DLSUFFIX): %.c - $(CC) $(CFLAGS) -shared -o $@ $< depend dep: - $(CC) -MM $(CFLAGS) *.c >depend + $(CC) -MM -MG $(CFLAGS) *.c > depend clean: - rm -f *~ $(MODULE) $(MODNAME).sql + $(RM) *~ $(OBJS) $(MODS) $(PROGRAM) depend $(OTHER_CLEAN) core log ifeq (depend,$(wildcard depend)) include depend diff --git a/contrib/array/README b/contrib/array/README new file mode 100644 index 0000000000..b072ebe397 --- /dev/null +++ b/contrib/array/README @@ -0,0 +1,49 @@ +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. |