Skip to content

Commit

Permalink
Note json array vs native array args
Browse files Browse the repository at this point in the history
  • Loading branch information
begriffs committed Jan 23, 2017
1 parent 1976806 commit e56ffe7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,26 @@ The client can call it by posting an object like
POST /rpc/add_them HTTP/1.1
{ "a": 1, "b": 2}
{ "a": 1, "b": 2 }
The keys of the object match the parameter names. Note that PostgreSQL converts parameter names to lowercase unless you quote them like :sql:`CREATE FUNCTION foo("mixedCase" text) ...`.

.. note::

We recommend using function arguments of type json to accept arrays from the client. To pass a PostgreSQL native array you'll need to quote it as a string:

.. code:: http
POST /rpc/native_array_func HTTP/1.1
{ "arg": "{1,2,3}" }
.. code:: http
POST /rpc/json_array_func HTTP/1.1
{ "arg": [1,2,3] }
PostgreSQL has four procedural languages that are part of the core distribution: PL/pgSQL, PL/Tcl, PL/Perl, and PL/Python. There are many other procedural languages distributed as additional extensions. Also, plain SQL can be used to write functions (as shown in the example above).

By default, a function is executed with the privileges of the user who calls it. This means that the user has to have all permissions to do the operations the procedure performs. Another option is to define the function with with the :code:`SECURITY DEFINER` option. Then only one permission check will take place, the permission to call the function, and the operations in the function will have the authority of the user who owns the function itself. See `PostgreSQL documentation <https://www.postgresql.org/docs/current/static/sql-createfunction.html>`_ for more details.
Expand Down

0 comments on commit e56ffe7

Please sign in to comment.