1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* array.h
|
2000-05-29 23:02:32 +02:00
|
|
|
* Utilities for the new array code. Contains prototypes from the
|
1997-09-07 07:04:48 +02:00
|
|
|
* following files:
|
|
|
|
* utils/adt/arrayfuncs.c
|
|
|
|
* utils/adt/arrayutils.c
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2003-08-08 23:42:59 +02:00
|
|
|
* $Id: array.h,v 1.45 2003/08/08 21:42:55 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef ARRAY_H
|
|
|
|
#define ARRAY_H
|
|
|
|
|
2000-05-29 23:02:32 +02:00
|
|
|
#include "fmgr.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/*
|
|
|
|
* Arrays are varlena objects, so must meet the varlena convention that
|
|
|
|
* the first int32 of the object contains the total object size in bytes.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-07-17 05:05:41 +02:00
|
|
|
int32 size; /* total array size (varlena requirement) */
|
1997-09-08 04:41:22 +02:00
|
|
|
int ndim; /* # of dimensions */
|
|
|
|
int flags; /* implementation flags */
|
2000-07-22 05:34:43 +02:00
|
|
|
/* flags field is currently unused, always zero. */
|
2002-08-26 19:54:02 +02:00
|
|
|
Oid elemtype; /* element type OID */
|
1997-09-08 22:59:27 +02:00
|
|
|
} ArrayType;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2003-06-27 02:33:26 +02:00
|
|
|
typedef struct ArrayBuildState
|
|
|
|
{
|
|
|
|
MemoryContext mcontext; /* where all the temp stuff is kept */
|
|
|
|
Datum *dvalues; /* array of accumulated Datums */
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2003-06-27 02:33:26 +02:00
|
|
|
/*
|
|
|
|
* The allocated size of dvalues[] is always a multiple of
|
|
|
|
* ARRAY_ELEMS_CHUNKSIZE
|
|
|
|
*/
|
|
|
|
#define ARRAY_ELEMS_CHUNKSIZE 64
|
|
|
|
int nelems; /* number of valid Datums in dvalues[] */
|
|
|
|
Oid element_type; /* data type of the Datums */
|
|
|
|
int16 typlen; /* needed info about datatype */
|
|
|
|
bool typbyval;
|
|
|
|
char typalign;
|
2003-08-08 23:42:59 +02:00
|
|
|
} ArrayBuildState;
|
2003-06-27 02:33:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* structure to cache type metadata needed for array manipulation
|
|
|
|
*/
|
|
|
|
typedef struct ArrayMetaState
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
Oid element_type;
|
|
|
|
int16 typlen;
|
|
|
|
bool typbyval;
|
|
|
|
char typalign;
|
|
|
|
char typdelim;
|
|
|
|
Oid typelem;
|
|
|
|
Oid typiofunc;
|
|
|
|
FmgrInfo proc;
|
2003-08-08 23:42:59 +02:00
|
|
|
} ArrayMetaState;
|
2003-06-27 02:33:26 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/*
|
|
|
|
* fmgr macros for array objects
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetArrayTypeP(X) ((ArrayType *) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetArrayTypePCopy(X) ((ArrayType *) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n))
|
2000-07-17 05:05:41 +02:00
|
|
|
#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x)
|
2000-07-17 05:05:41 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
2000-07-22 05:34:43 +02:00
|
|
|
* Access macros for array header fields.
|
|
|
|
*
|
1996-08-28 03:59:28 +02:00
|
|
|
* ARR_DIMS returns a pointer to an array of array dimensions (number of
|
|
|
|
* elements along the various array axes).
|
|
|
|
*
|
|
|
|
* ARR_LBOUND returns a pointer to an array of array lower bounds.
|
|
|
|
*
|
|
|
|
* That is: if the third axis of an array has elements 5 through 10, then
|
2003-07-14 22:34:18 +02:00
|
|
|
* ARR_DIMS(a)[2] == 6 and ARR_LBOUND(a)[2] == 5.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Unlike C, the default lower bound is 1.
|
|
|
|
*/
|
2000-07-22 05:34:43 +02:00
|
|
|
#define ARR_SIZE(a) (((ArrayType *) (a))->size)
|
|
|
|
#define ARR_NDIM(a) (((ArrayType *) (a))->ndim)
|
2002-08-26 19:54:02 +02:00
|
|
|
#define ARR_ELEMTYPE(a) (((ArrayType *) (a))->elemtype)
|
2000-07-22 05:34:43 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ARR_DIMS(a) \
|
2000-07-22 05:34:43 +02:00
|
|
|
((int *) (((char *) (a)) + sizeof(ArrayType)))
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ARR_LBOUND(a) \
|
2000-07-22 05:34:43 +02:00
|
|
|
((int *) (((char *) (a)) + sizeof(ArrayType) + \
|
|
|
|
(sizeof(int) * ARR_NDIM(a))))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The total array header size for an array of dimension n (in bytes).
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ARR_OVERHEAD(n) \
|
2000-07-22 05:34:43 +02:00
|
|
|
(MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (n)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-07-22 05:34:43 +02:00
|
|
|
/*
|
|
|
|
* Returns a pointer to the actual array data.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-07-22 05:34:43 +02:00
|
|
|
#define ARR_DATA_PTR(a) \
|
|
|
|
(((char *) (a)) + ARR_OVERHEAD(ARR_NDIM(a)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in arrayfuncs.c
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
extern Datum array_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_out(PG_FUNCTION_ARGS);
|
2003-05-09 00:19:58 +02:00
|
|
|
extern Datum array_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_send(PG_FUNCTION_ARGS);
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
extern Datum array_length_coerce(PG_FUNCTION_ARGS);
|
2000-06-13 09:35:40 +02:00
|
|
|
extern Datum array_eq(PG_FUNCTION_ARGS);
|
2003-06-27 02:33:26 +02:00
|
|
|
extern Datum array_ne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_lt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_gt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_le(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_ge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum btarraycmp(PG_FUNCTION_ARGS);
|
2000-06-13 09:35:40 +02:00
|
|
|
extern Datum array_dims(PG_FUNCTION_ARGS);
|
2002-11-08 18:27:03 +01:00
|
|
|
extern Datum array_lower(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_upper(PG_FUNCTION_ARGS);
|
2003-04-09 01:20:04 +02:00
|
|
|
extern Datum array_type_coerce(PG_FUNCTION_ARGS);
|
2000-06-13 09:35:40 +02:00
|
|
|
|
|
|
|
extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx,
|
2002-08-26 19:54:02 +02:00
|
|
|
int arraylen, int elmlen, bool elmbyval, char elmalign,
|
|
|
|
bool *isNull);
|
2000-06-13 09:35:40 +02:00
|
|
|
extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
|
2001-03-22 05:01:46 +01:00
|
|
|
Datum dataValue,
|
2002-08-26 19:54:02 +02:00
|
|
|
int arraylen, int elmlen, bool elmbyval, char elmalign,
|
|
|
|
bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts,
|
2001-03-22 05:01:46 +01:00
|
|
|
int *upperIndx, int *lowerIndx,
|
2002-08-26 19:54:02 +02:00
|
|
|
int arraylen, int elmlen, bool elmbyval, char elmalign,
|
|
|
|
bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts,
|
2001-03-22 05:01:46 +01:00
|
|
|
int *upperIndx, int *lowerIndx,
|
|
|
|
ArrayType *srcArray,
|
2002-08-26 19:54:02 +02:00
|
|
|
int arraylen, int elmlen, bool elmbyval, char elmalign,
|
|
|
|
bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
|
2000-05-29 23:02:32 +02:00
|
|
|
extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType);
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
extern ArrayType *construct_array(Datum *elems, int nelems,
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid elmtype,
|
|
|
|
int elmlen, bool elmbyval, char elmalign);
|
2003-04-09 01:20:04 +02:00
|
|
|
extern ArrayType *construct_md_array(Datum *elems,
|
2003-08-04 02:43:34 +02:00
|
|
|
int ndims,
|
|
|
|
int *dims,
|
|
|
|
int *lbs,
|
|
|
|
Oid elmtype, int elmlen, bool elmbyval, char elmalign);
|
2000-07-17 05:05:41 +02:00
|
|
|
extern void deconstruct_array(ArrayType *array,
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid elmtype,
|
|
|
|
int elmlen, bool elmbyval, char elmalign,
|
|
|
|
Datum **elemsp, int *nelemsp);
|
2003-08-08 23:42:59 +02:00
|
|
|
extern ArrayBuildState *accumArrayResult(ArrayBuildState *astate,
|
2003-08-04 02:43:34 +02:00
|
|
|
Datum dvalue, bool disnull,
|
|
|
|
Oid element_type,
|
|
|
|
MemoryContext rcontext);
|
2003-08-08 23:42:59 +02:00
|
|
|
extern Datum makeArrayResult(ArrayBuildState *astate,
|
2003-08-04 02:43:34 +02:00
|
|
|
MemoryContext rcontext);
|
2003-08-08 23:42:59 +02:00
|
|
|
extern Datum makeMdArrayResult(ArrayBuildState *astate, int ndims,
|
2003-08-04 02:43:34 +02:00
|
|
|
int *dims, int *lbs, MemoryContext rcontext);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in arrayutils.c
|
|
|
|
*/
|
|
|
|
|
2000-07-22 05:34:43 +02:00
|
|
|
extern int ArrayGetOffset(int n, int *dim, int *lb, int *indx);
|
|
|
|
extern int ArrayGetOffset0(int n, int *tup, int *scale);
|
|
|
|
extern int ArrayGetNItems(int n, int *a);
|
1998-09-01 05:29:17 +02:00
|
|
|
extern void mda_get_range(int n, int *span, int *st, int *endp);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern void mda_get_prod(int n, int *range, int *prod);
|
|
|
|
extern void mda_get_offset_values(int n, int *dist, int *prod, int *span);
|
|
|
|
extern int mda_next_tuple(int n, int *curr, int *span);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2003-04-09 01:20:04 +02:00
|
|
|
/*
|
|
|
|
* prototypes for functions defined in array_userfuncs.c
|
|
|
|
*/
|
|
|
|
extern Datum array_push(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_cat(PG_FUNCTION_ARGS);
|
|
|
|
|
2003-06-27 02:33:26 +02:00
|
|
|
extern ArrayType *create_singleton_array(FunctionCallInfo fcinfo,
|
2003-08-04 02:43:34 +02:00
|
|
|
Oid element_type,
|
|
|
|
Datum element,
|
|
|
|
int ndims);
|
2003-04-09 01:20:04 +02:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* ARRAY_H */
|