How to pass an array parameter to a stored procedure

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Niels
Posts: 4
Joined: Fri 20 Apr 2012 05:24

How to pass an array parameter to a stored procedure

Post by Niels » Tue 02 Oct 2018 09:03

Hi,
I have a stored procedure with the following header:

Code: Select all

CREATE OR REPLACE FUNCTION "UpdateClassGeneral" (
  "ActiveRatios" integer [],
  "ActiveClass" varchar,
  "ActiveClassProjCodesSQL" varchar []
)
How can I pass the integer- and varchar array to my TPgStoredProc component?
There is no documentation for it available?
Or is there a work around?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: How to pass an array parameter to a stored procedure

Post by azyk » Tue 02 Oct 2018 12:48

You should pass array parameter as string value of TPgStoredProc parameter. For example:

Code: Select all

  PgStoredProc1.StoredProcName := '"UpdateClassGeneral"';
  PgStoredProc1.Prepare;

  PgStoredProc1.ParamByName('ActiveRatios').AsString := '{1,2,3}';
  PgStoredProc1.ParamByName('ActiveClass').Value := 'some text';
  PgStoredProc1.ParamByName('ActiveClassProjCodesSQL').AsString := '{PgDAC,pass,array param}';

  PgStoredProc1.ExecProc;

Niels
Posts: 4
Joined: Fri 20 Apr 2012 05:24

Re: How to pass an array parameter to a stored procedure

Post by Niels » Wed 03 Oct 2018 02:19

Works perfectly now.
Thank you!

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: How to pass an array parameter to a stored procedure

Post by azyk » Wed 03 Oct 2018 08:13

If you have any questions about our products, feel free to contact us.

Post Reply