Du bør bruge funktionen construct_array
eller construct_md_array
#include "catalog/pg_type.h"PG_FUNCTION_INFO_V1(array_four);Datumarray_four(PG_FUNCTION_ARGS){ Datumelementer[4]; ArrayType *array; elementer[0] =PG_GETARG_DATUM(0); elementer[1] =PG_GETARG_DATUM(1); elementer[2] =PG_GETARG_DATUM(2); elementer[3] =PG_GETARG_DATUM(3); array =construct_array(elementer, 4, INT8OID, 8, sand, 'd'); PG_RETURN_POINTER(array);}
anden variant:
Datumarray_four(PG_FUNCTION_ARGS){ Datumelementer[4]; ArrayType *array; int i; for (i =0; i <4; i++) elementer[i] =Int64GetDatum(i); array =construct_array(elementer, 4, INT8OID, 8, sand, 'd'); PG_RETURN_POINTER(array);}
registrering:
OPRET FUNKTION array_four(int, int, int, int)RETURNERER int[]SOM 'MODULE_PATHNAME'SPROG C UDVINKELLIG STRICT;
test:
postgres=# vælg array_four(10,20,30,40);┌───────────────┐│ array_four ┐➕➐➕ ═══════╡│ {10,20,30,40} │└────────────────)kode