Skip to content

Commit f01d5bf

Browse files
committed
docs: reorder computed relationships for clarity
Ensure the function inlining is mentioned first
1 parent 0ae1cdf commit f01d5bf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/references/api/resource_embedding.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ Computed Relationships
251251

252252
You can manually define relationships by using functions. This is useful for database objects that can't define foreign keys, like `Foreign Data Wrappers <https://wiki.postgresql.org/wiki/Foreign_data_wrappers>`_.
253253

254+
Computed relationships have good performance as their intended design enable `function inlining <https://wiki.postgresql.org/wiki/Inlining_of_SQL_functions#Inlining_conditions_for_table_functions>`_.
255+
256+
.. important::
257+
258+
- Always use ``SETOF`` when creating computed relationships. Functions can return a table without using ``SETOF``, but bear in mind that PostgreSQL will not inline them. e.g. ``RETURNS <table_name>`` is not inlinable.
259+
254260
Assuming there's a foreign table ``premieres`` that we want to relate to ``films``.
255261

256262
.. code-block:: postgres
@@ -283,6 +289,10 @@ The name of the function ``film`` is arbitrary and can be used to do the embeddi
283289
".."
284290
]
285291
292+
.. warning::
293+
294+
- Make sure to correctly label the ``to-one`` part of the relationship. When using the ``ROWS 1`` estimation, PostgREST will expect a single row to be returned. If that is not the case, it will unnest the embedding and return repeated values for the top level resource.
295+
286296
Now let's define the opposite one-to-many relationship.
287297

288298
.. code-block:: postgres
@@ -331,12 +341,6 @@ Thanks to overloaded functions, you can use the same function name for different
331341
332342
Computed relationships have good performance as their intended design enable `function inlining <https://wiki.postgresql.org/wiki/Inlining_of_SQL_functions#Inlining_conditions_for_table_functions>`_.
333343

334-
.. warning::
335-
336-
- Always use ``SETOF`` when creating computed relationships. Functions can return a table without using ``SETOF``, but bear in mind that PostgreSQL will not inline them.
337-
338-
- Make sure to correctly label the ``to-one`` part of the relationship. When using the ``ROWS 1`` estimation, PostgREST will expect a single row to be returned. If that is not the case, it will unnest the embedding and return repeated values for the top level resource.
339-
340344
.. _embed_disamb:
341345
.. _target_disamb:
342346
.. _hint_disamb:

0 commit comments

Comments
 (0)