From 5cabcfccce4b8b826c9b30828f3012b7926a6946 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 26 Aug 2002 17:54:02 +0000 Subject: Modify array operations to include array's element type OID in the array header, and to compute sizing and alignment of array elements the same way normal tuple access operations do --- viz, using the tupmacs.h macros att_addlength and att_align. This makes the world safe for arrays of cstrings or intervals, and should make it much easier to write array-type-polymorphic functions; as examples see the cleanups of array_out and contrib/array_iterator. By Joe Conway and Tom Lane. --- src/include/utils/array.h | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/include/utils/array.h') diff --git a/src/include/utils/array.h b/src/include/utils/array.h index 459d2caaff..b0920c70d9 100644 --- a/src/include/utils/array.h +++ b/src/include/utils/array.h @@ -10,13 +10,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: array.h,v 1.32 2002/06/20 20:29:52 momjian Exp $ - * - * NOTES - * XXX the data array should be MAXALIGN'd -- currently we only INTALIGN - * which is NOT good enough for, eg, arrays of Interval. Changing this - * will break existing user tables so hold off until we have some other - * reason to break user tables (like WAL). + * $Id: array.h,v 1.33 2002/08/26 17:54:02 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -35,6 +29,7 @@ typedef struct int ndim; /* # of dimensions */ int flags; /* implementation flags */ /* flags field is currently unused, always zero. */ + Oid elemtype; /* element type OID */ } ArrayType; /* @@ -61,6 +56,7 @@ typedef struct */ #define ARR_SIZE(a) (((ArrayType *) (a))->size) #define ARR_NDIM(a) (((ArrayType *) (a))->ndim) +#define ARR_ELEMTYPE(a) (((ArrayType *) (a))->elemtype) #define ARR_DIMS(a) \ ((int *) (((char *) (a)) + sizeof(ArrayType))) @@ -90,29 +86,31 @@ extern Datum array_eq(PG_FUNCTION_ARGS); extern Datum array_dims(PG_FUNCTION_ARGS); extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx, - bool elmbyval, int elmlen, - int arraylen, bool *isNull); + int arraylen, int elmlen, bool elmbyval, char elmalign, + bool *isNull); extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, - bool elmbyval, int elmlen, - int arraylen, bool *isNull); + int arraylen, int elmlen, bool elmbyval, char elmalign, + bool *isNull); extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts, int *upperIndx, int *lowerIndx, - bool elmbyval, int elmlen, - int arraylen, bool *isNull); + int arraylen, int elmlen, bool elmbyval, char elmalign, + bool *isNull); extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts, int *upperIndx, int *lowerIndx, ArrayType *srcArray, - bool elmbyval, int elmlen, - int arraylen, bool *isNull); + int arraylen, int elmlen, bool elmbyval, char elmalign, + bool *isNull); extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType); extern ArrayType *construct_array(Datum *elems, int nelems, - bool elmbyval, int elmlen, char elmalign); + Oid elmtype, + int elmlen, bool elmbyval, char elmalign); extern void deconstruct_array(ArrayType *array, - bool elmbyval, int elmlen, char elmalign, - Datum **elemsp, int *nelemsp); + Oid elmtype, + int elmlen, bool elmbyval, char elmalign, + Datum **elemsp, int *nelemsp); /* -- cgit v1.2.1