integer arrays

Started by mlwover 24 years ago2 messages
#1mlw
markw@mohawksoft.com

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#1)
Re: integer arrays

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