From cacbbc31fee8bb072f870b77266179b7c84c2dc9 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 10 Aug 2023 02:27:21 -0500 Subject: [PATCH] add setof record functions --- docs/references/api/stored_procedures.rst | 33 +++++++++++++++++++++++ postgrest.dict | 1 + 2 files changed, 34 insertions(+) diff --git a/docs/references/api/stored_procedures.rst b/docs/references/api/stored_procedures.rst index e5098864b..9aa28d9e2 100644 --- a/docs/references/api/stored_procedures.rst +++ b/docs/references/api/stored_procedures.rst @@ -420,6 +420,39 @@ PostgREST will detect if the function is scalar or table-valued and will shape t To manually choose a return format such as binary, plain text or XML, see the section :ref:`scalar_return_formats`. +.. _untyped_functions: + +Untyped functions +----------------- + +Functions that return ``record`` or ``SETOF record`` are supported: + +.. code-block:: postgres + + create function projects_setof_record() returns setof record as $$ + select * from projects; + $$ language sql; + +.. tabs:: + + .. code-tab:: http + + GET /rpc/projects_setof_record HTTP/1.1 + + .. code-tab:: bash Curl + + curl "http://localhost:3000/rpc/projects_setof_record" + +.. code-block:: json + + [{"id":1,"name":"Windows 7","client_id":1}, + {"id":2,"name":"Windows 10","client_id":1}, + {"id":3,"name":"IOS","client_id":2}] + +However note that they will fail when trying to use :ref:`v_filter` and :ref:`h_filter` on them. + +So while they can be used for quick tests, it's recommended to always choose a strict return type for the function. + Overloaded functions -------------------- diff --git a/postgrest.dict b/postgrest.dict index c5070d1dd..f4aa4dd42 100644 --- a/postgrest.dict +++ b/postgrest.dict @@ -182,6 +182,7 @@ unicode unikernel unix updatable +Untyped UPSERT Upsert upsert