How to set array parameter in sql statement?

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for PostgreSQL in Delphi and C++Builder
Post Reply
yellowfever13
Posts: 4
Joined: Wed 24 Jul 2013 16:17

How to set array parameter in sql statement?

Post by yellowfever13 » Tue 30 Jul 2013 21:29

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!

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: How to set array parameter in sql statement?

Post by DemetrionQ » Wed 31 Jul 2013 11:23

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.

Post Reply