Best way to construct PostgreSQL ArrayType (_int4) from C int array

From: Adrian Schreyer <ams214(at)cam(dot)ac(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Best way to construct PostgreSQL ArrayType (_int4) from C int array
Date: 2011-04-27 11:02:36
Message-ID: BANLkTim6L6NCgDP3cUvA4hZjPLpPU1ZLeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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)?

Cheers,

Adrian

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2011-04-27 13:08:19 Re: Create Database automatacally after silent installation of postgresql. ?
Previous Message hirenlad 2011-04-27 07:47:46 Create Database automatacally after silent installation of postgresql. ?