Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
fix headlines
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Mar 25, 2022
1 parent 23a9665 commit 03c6d9c
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1579,40 +1579,12 @@ To bulk insert JSON post an array of objects having all-matching keys
]
EOF

.. _update:

Updates
=======

To update a row or rows in a table, use the PATCH verb. Use :ref:`h_filter` to specify which record(s) to update. Here is an example query setting the :code:`category` column to child for all people below a certain age.

.. tabs::

.. code-tab:: http

PATCH /people?age=lt.13 HTTP/1.1

{ "category": "child" }

.. code-tab:: bash Curl

curl "http://localhost:3000/people?age=lt.13" \
-X PATCH -H "Content-Type: application/json" \
-d '{ "category": "child" }'

Updates also support :code:`Prefer: return=representation` plus :ref:`v_filter`.

.. warning::

Beware of accidentally updating every row in a table. To learn to prevent that see :ref:`block_fulltable`.

.. _specify_columns:

Specifying Columns
==================
------------------

By using the :code:`columns` query parameter it's possible to specify the payload keys that will be inserted/updated
and ignore the rest of the payload.
By using the :code:`columns` query parameter it's possible to specify the payload keys that will be inserted and ignore the rest of the payload.

.. tabs::

Expand Down Expand Up @@ -1652,10 +1624,37 @@ In this case, only **source**, **publication_date** and **figure** will be inser
Using this also has the side-effect of being more efficient for :ref:`bulk_insert` since PostgREST will not process the JSON and
it'll send it directly to PostgreSQL.

.. _update:

Updates
=======

To update a row or rows in a table, use the PATCH verb. Use :ref:`h_filter` to specify which record(s) to update. Here is an example query setting the :code:`category` column to child for all people below a certain age.

.. tabs::

.. code-tab:: http

PATCH /people?age=lt.13 HTTP/1.1

{ "category": "child" }

.. code-tab:: bash Curl

curl "http://localhost:3000/people?age=lt.13" \
-X PATCH -H "Content-Type: application/json" \
-d '{ "category": "child" }'

Updates also support :code:`Prefer: return=representation` plus :ref:`v_filter`.

.. warning::

Beware of accidentally updating every row in a table. To learn to prevent that see :ref:`block_fulltable`.

.. _upsert:

UPSERT
------
======

You can make an UPSERT with :code:`POST` and the :code:`Prefer: resolution=merge-duplicates` header:

Expand Down Expand Up @@ -1693,7 +1692,7 @@ By default, UPSERT operates based on the primary key columns, you must specify a
.. _on_conflict:

On Conflict
~~~~~~~~~~~
-----------

By specifying the ``on_conflict`` query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.

Expand Down Expand Up @@ -1726,7 +1725,7 @@ By specifying the ``on_conflict`` query parameter, you can make UPSERT work on a
.. _upsert_put:

PUT
~~~
---

A single row UPSERT can be done by using :code:`PUT` and filtering the primary key columns with :code:`eq`:

Expand Down

0 comments on commit 03c6d9c

Please sign in to comment.