Best way to construct PostgreSQL ArrayType (_int4) from C int array - Mailing list pgsql-general

From Adrian Schreyer
Subject Best way to construct PostgreSQL ArrayType (_int4) from C int array
Date
Msg-id BANLkTim6L6NCgDP3cUvA4hZjPLpPU1ZLeA@mail.gmail.com
Whole thread Raw
Responses Re: Best way to construct PostgreSQL ArrayType (_int4) from C int array
List 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

pgsql-general by date:

Previous
From: Toby Corkindale
Date:
Subject: Re: tuning on ec2
Next
From: hirenlad
Date:
Subject: Create Database automatacally after silent installation of postgresql. ?