Skip to content

Commit

Permalink
docs: add enums to working with data types how-to
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenceisla committed Feb 29, 2024
1 parent a1480c7 commit 0f45a9c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/how-tos/working-with-postgresql-data-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,48 @@ You can use other comparative filters and also all the `PostgreSQL special date/
"due_date": "2022-02-27T06:00:00-05:00"
}
]
Enums
-----
You can handle :ref:`Enumerated Types <https://www.postgresql.org/docs/current/datatype-enum.html>` using string representations:
.. code-block:: postgres
create type letter_size as enum ('s','m','l','xl');
create table products (
id int primary key generated always as identity,
name text,
size letter_size
);
To insert or update the value use a string:
.. code-bloc:: bash
curl -X POST "http://localhost:3000/products" \
-H "Content-Type: application/json" \
-d @- << EOF
{ "name": "t-shirt", "size": "l" }
EOF
You can then query and filter the enum using the compatible :ref:`operators <operators>`.
For example, to get all the products larger than `m` and ordering them by their size:
.. code-block:: bash
curl "http://localhost:3000/products?select=name,size&size=gt.m&order=size"
.. code-block:: json
[
{
"name": "t-shirt,
"size": "l"
},
{
"name": "hoodie,
"size": "xl"
}
]

0 comments on commit 0f45a9c

Please sign in to comment.