Re: Best way to construct PostgreSQL ArrayType (_int4) from C int array
От | Merlin Moncure |
---|---|
Тема | Re: Best way to construct PostgreSQL ArrayType (_int4) from C int array |
Дата | |
Msg-id | BANLkTi=8mc6+5t+BYXkaMNhp6miChNS=7Q@mail.gmail.com обсуждение исходный текст |
Ответ на | Best way to construct PostgreSQL ArrayType (_int4) from C int array (Adrian Schreyer <ams214@cam.ac.uk>) |
Ответы |
Re: Best way to construct PostgreSQL ArrayType (_int4) from
C int array
|
Список | pgsql-general |
On Wed, Apr 27, 2011 at 6:02 AM, Adrian Schreyer <ams214@cam.ac.uk> wrote: > At the moment I am using the following code to construct a PostgreSQL > array from a C array in my C extension but I am not so sure if this is > really the best solution: > > const int *data = array.data(); // C array > Datum *d = (Datum *) palloc(sizeof(Datum) * size); > > for (int i = 0; i < size; i++) d[i] = Int32GetDatum(data[i]); > > ArrayType *a = construct_array(d, size, INT4OID, sizeof(int4), true, 'i'); > > Is this okay or is there a better solution (existing function in the > PostgreSQL source for example)? That's pretty much the best way AFAIK. Int32GetDatum doesn't do anything fancy -- it's just a 32 bit mask/assignment. constructing the array at once is going to be a lot better than incrementally creating it. Do you expect the arrays to be large, say bigger than 10k elements? merlin
В списке pgsql-general по дате отправления: