Page 1 of 1

How to set array parameter in sql statement?

Posted: Tue 30 Jul 2013 21:29
by yellowfever13
I can't figure out how to populate an array into my statement, I have googled and searched this forum with no results.

example: "insert into mytable(someArray) values (:myArray);" //myArray is integer[10]

qry->ParamByName("myArray")->Value = ?????

I've tried various ways of setting this and get different errors each time. Help! Thanks!

Re: How to set array parameter in sql statement?

Posted: Wed 31 Jul 2013 11:23
by DemetrionQ
Hello.

Devart dbExpress Driver for PostgreSQL doesn't support arrays. As a workaround, you can use the following approaches:

1) If you save data to fields with array types (e.g., integer[]), you can list all the elements directly in the SQL query text, for example:

Code: Select all

insert into mytable(someArray) values (ARRAY[42, 2, 3, 5, 7, 42]);
You can read more about using PostgreSQL server array types at http://www.postgresql.org/docs/9.1/static/arrays.html

2) If you save data to bytea fields, you can copy data from the array to TMemoryStream, and then load the data to a parameter using the TParam.LoadFromStream method.