Thread: integer arrays

integer arrays

From
mlw
Date:
I have looked and I have looked, it is not immediately clear to me how integer
arrays are passed to C function.

create table fubar (vars integer[]) ;

select c_function(vars) from fubar;

insert into fubar (vars) values ('{1,2,3,4,5,6}');


........

extern "C" c_function (varlena var)
{int * pn = (int *)VARDATA(var);
}

Now, what should "pn" have in it? I don't see my values until later on in the
array. I guess I am asking is what is the format of this type, and more
importantly, where is it documented. I looked in catalog and pg_types but it
wasn't clear it was defined there.


-- 

I'm not offering myself as an example; every life evolves by its own laws.
------------------------
http://www.mohawksoft.com


Re: integer arrays

From
Tom Lane
Date:
mlw <markw@mohawksoft.com> writes:
> I have looked and I have looked, it is not immediately clear to me how
> integer arrays are passed to C function.

See src/include/utils/array.h, also src/backend/utils/adt/arrayfuncs.c
and src/backend/utils/adt/arrayutils.c.  Beware: this code is pretty
messy.
        regards, tom lane