Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux