From 06dba3953f388190a89d7bdc2145013aab067d2d Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 23 Oct 2020 22:06:49 +0200 Subject: [PATCH] calling variadic functions --- api.rst | 39 +++++++++++++++++++++++++++++++++++++-- releases/upcoming.rst | 2 ++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/api.rst b/api.rst index 6fd9c4ff9..9303d9528 100644 --- a/api.rst +++ b/api.rst @@ -1215,8 +1215,6 @@ as in ``{1,2,3,4}``. Note that the curly brackets have to be urlencoded(``{`` is GET /rpc/plus_one?arr=%7B1,2,3,4%7D' HTTP/1.1 - [2,3,4,5] - .. note:: For versions prior to PostgreSQL 10, to pass a PostgreSQL native array on a POST payload, you need to quote it and use an array literal: @@ -1231,6 +1229,43 @@ as in ``{1,2,3,4}``. Note that the curly brackets have to be urlencoded(``{`` is .. _s_procs_variadic: +Calling variadic functions +-------------------------- + +You can call a variadic function by passing a json array in a POST request: + +.. code-block:: postgres + + create function plus_one(variadic v int[]) returns int[] as $$ + SELECT array_agg(n + 1) FROM unnest($1) AS n; + $$ language sql; + +.. code-block:: http + + POST /rpc/plus_one HTTP/1.1 + Content-Type: application/json + + {"v": [1,2,3,4]} + +.. code-block:: json + + [2,3,4,5] + +In a GET request, you can repeat the same parameter name: + +.. code-block:: http + + GET /rpc/plus_one?v=1&v=2&v=3&v=4 HTTP/1.1 + +Repeating also works in POST requests with ``Content-Type: application/x-www-form-urlencoded``: + +.. code-block:: http + + POST /rpc/plus_one HTTP/1.1 + Content-Type: application/x-www-form-urlencoded + + v=1&v=2&v=3&v=4 + Scalar functions ---------------- diff --git a/releases/upcoming.rst b/releases/upcoming.rst index 73a123922..c6d9ec27d 100644 --- a/releases/upcoming.rst +++ b/releases/upcoming.rst @@ -12,6 +12,8 @@ Added * Allow http status override through the :ref:`response.status ` GUC. |br| -- `@steve-chavez `_ +* Allow :ref:`s_procs_variadic`. + |br| -- `@wolfgangwalther `_ Fixed -----