Note json array vs native array args

This commit is contained in:
Joe Nelson
2017-01-22 20:36:27 -08:00
parent 19768064dd
commit e56ffe7b5e
+17 -1
View File
@@ -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.