Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a psql-C function with an undefined length list of integers (GIDs for example).

An erratic example using V0 function definition that works is like:

int mytest4(int *x, int i){
  int *a  = &(x[6]);
  int j;
  for (j = 0; j < i; j++)
     printf("Passed on %d", a[j]); // sent to logfile
  return a[i];

My question concerns the V1 functions to read an int array. I don't understand how to do

Datum mytest5(PG_FUNCTION_ARGS){
int *x = PG_GETARG_???(0);
int i = PG_GETARG_INT32(1);

Does anyone know how to write the same function, please??

share|improve this question
You can find som information on the PostGIS wiki: – Nicklas Avén Jun 26 '12 at 6:22
Thank you Nicklas, your link will certainly be helpful to me in a day or two... – Aname Jun 26 '12 at 13:43
up vote 0 down vote accepted

Okay that was a tricky one, you just have to force cast using

int *x = (int *) PG_GETARG_POINTER(1);

and that should do the job...

I still don't get everything, but /usr/include/postgresql/9.1/server/utils/array.h says :

  • A standard varlena array has the following internal structure:
    • - standard varlena header word
    • - number of dimensions of the array
    • - offset to stored data, or 0 if no nulls bitmap
    • - element type OID
    • - length of each array axis (C array of int)
    • - lower boundary of each dimension (C array of int)
    • - bitmap showing locations of nulls (OPTIONAL)
    • - whatever is the stored data
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.