PHP配列を次の関数に渡すことにほとんど成功していません。
$recipients = array();
$recipients['6c2f7451-bac8-4cdd-87ce-45d55d152078'] = 5.00;
$recipients['8c2f3421-bac8-4cdd-87ce-45d55d152074'] = 10.00;
$originator = '5630cc6d-f994-43ff-abec-1ebb74d39a3f';
$params = array($originator, $recipients);
pg_query_params(_conn, 'SELECT widgetallocationrequest($1, $2)', $params);
$results = pg_fetch_all(pg_query_params);
...
この関数は、カスタム タイプの配列を受け入れます。
CREATE TYPE widgetallocationrequest AS (id uuid, amount numeric(13,4));
各項目を列挙し、アクションを実行します。
CREATE FUNCTION distributeWidgets(pid uuid, precipients widgetallocationrequest[])
RETURNS BOOLEAN AS
$BODY$
{
FOREACH v_recipient IN ARRAY precipients
LOOP
...do something
END LOOP;
}
RETURN TRUE;
END;
$BODY$
LANGUAGE plpgsql VOLATILE STRICT
COST 100;
***(if the specific code sample contains errors it's only pseudocode, i'm really just looking for the best way to pass a php array to a postgres custom type array as a parameter so it can be enumerated in the postgres function)***
更新: 次のようにして、postgres から直接 (PHP からではなく) 関数を正常に呼び出すことができます。
SELECT distributeWidgets('5630cc6d-f994-43ff-abec-1ebb74d39a3f',
ARRAY[('ac747f0e-93d4-43a9-bc5b-09df06593239', '5.00'), ('8c2f3421-bac8-4cdd-87ce-45d55d152074', '10.00')]::widgetallocationrequest[]);
しかし、この postgres の例を PHP に変換する方法がまだわかりません
以下の提案を試してみましたが、参照された関数からの出力で次のエラーが発生します。
関数からの文字列は次のとおりです。
'SELECT account.hldtoexpalloc('0d6311cc-0d74-4a32-8cf9-87835651e1ee', '0124a045-b2e8-4a9f-b8c4-43b1e4cf638d', '{{\"6c2f7451-bac8-4cdd-87ce-45d55d152078\",5.00},{\"8c2f3421-bac8-4cdd-87ce-45d55d152074\",10.00}}')'