Proposed patch for contrib/cube
От | Joshua Reich |
---|---|
Тема | Proposed patch for contrib/cube |
Дата | |
Msg-id | 44BBCAEF.5060007@root.net обсуждение исходный текст |
Ответы |
Re: Proposed patch for contrib/cube
|
Список | pgsql-hackers |
Hi, I use the cube datatype a fair bit, and one thing I have always wanted is the ability to do this: pg=# select cube_from_arrays('{1,2,3}'::float[], '{3,5,6}'::float[]); cube_from_arrays --------------------- (1, 2, 3),(3, 5, 6) (1 row) That is - build a cube by specifying 2 arrays, one for the UR coordinate, one for LL. I hope people find this useful, and if so, we can add it to contrib/cube. Source is attached. Thanks, Joshua Reich (jdigittl on #postgresql) #include "postgres.h" #include "utils/array.h" #include "cubedata.h" /* contrib/cube */ /* ** CREATE OR REPLACE FUNCTION cube_from_arrays(float[], float[]) RETURNS cube ** AS 'ordermatch' ** LANGUAGE C; */ NDBOX *cube_from_arrays (ArrayType *ur, ArrayType *ll); /* ** Taken from the intarray contrib header */ #define ARRPTR(x) ( (double *) ARR_DATA_PTR(x) ) #define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x)) /* ** Allows the construction of a cube from 2 float[]'s */ NDBOX *cube_from_arrays (ArrayType *ur, ArrayType *ll) { int i; int dim; int size; NDBOX *result; double *dur, *dll; dim = ARRNELEMS(ur); if (ARRNELEMS(ll) < dim) { /* ** If the array's are not of equal length, use the length ** of the shorter array. */ dim = ARRNELEMS(ll); } dur = ARRPTR(ur); dll = ARRPTR(ll); size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim; result = (NDBOX *) palloc (size); memset (result, 0, size); result->size = size; result->dim = dim; for (i=0; i<dim; i++) { result->x[i] = dur[i]; result->x[i+dim] = dll[i]; } return result; }
В списке pgsql-hackers по дате отправления: