docs: Use code-block postgres consistently
This commit is contained in:
committed by
Wolfgang Walther
parent
553ac79d9b
commit
fcd29caecf
@@ -11,7 +11,7 @@ PostgREST automatically serves a full `OpenAPI <https://www.openapis.org/>`_ des
|
||||
|
||||
For extra customization, the OpenAPI output contains a "description" field for every `SQL comment <https://www.postgresql.org/docs/current/sql-comment.html>`_ on any database object. For instance,
|
||||
|
||||
.. code-block:: sql
|
||||
.. code-block:: postgres
|
||||
|
||||
COMMENT ON SCHEMA mammals IS
|
||||
'A warm-blooded vertebrate animal of a class that is distinguished by the secretion of milk by females for the nourishment of the young';
|
||||
@@ -26,7 +26,7 @@ These unsavory comments will appear in the generated JSON as the fields, ``info.
|
||||
|
||||
Also if you wish to generate a ``summary`` field you can do it by having a multiple line comment, the ``summary`` will be the first line and the ``description`` the lines that follow it:
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
COMMENT ON TABLE entities IS
|
||||
$$Entities summary
|
||||
@@ -37,7 +37,7 @@ Also if you wish to generate a ``summary`` field you can do it by having a multi
|
||||
|
||||
Similarly, you can override the API title by commenting the schema.
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
COMMENT ON SCHEMA api IS
|
||||
$$FooBar API
|
||||
|
||||
@@ -236,7 +236,7 @@ Single JSON object as Function Parameter
|
||||
|
||||
:code:`Prefer: params=single-object` allows sending the JSON request body as the single argument of a :ref:`function <s_procs>`.
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE FUNCTION mult_them(param json) RETURNS int AS $$
|
||||
SELECT (param->>'x')::int * (param->>'y')::int
|
||||
|
||||
@@ -178,7 +178,7 @@ The join table determines many-to-many relationships. It must contain foreign ke
|
||||
|
||||
The join table is also detected if the composite key has additional columns.
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create table roles(
|
||||
id int generated always as identity,
|
||||
@@ -214,7 +214,7 @@ One-to-one relationships are detected in two ways.
|
||||
- When the foreign key is a primary key as specified in the :ref:`sample film database <erd_film>`.
|
||||
- When the foreign key has a unique constraint.
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create table technical_specs(
|
||||
film_id int references films(id) unique,
|
||||
@@ -246,7 +246,7 @@ You can manually define relationships by using functions. This is useful for dat
|
||||
|
||||
Assuming there's a foreign table ``premieres`` that we want to relate to ``films``.
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create foreign table premieres (
|
||||
id integer,
|
||||
@@ -478,7 +478,7 @@ Recursive One-To-One
|
||||
|
||||
To get either side of the Recursive One-To-One relationship, create the functions:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function predecessor(presidents) returns setof presidents rows 1 as $$
|
||||
select * from presidents where id = $1.predecessor_id
|
||||
@@ -530,7 +530,7 @@ Recursive One-To-Many
|
||||
|
||||
To get the One-To-Many embedding, that is, the supervisors with their supervisees, create a function like this one:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function supervisees(employees) returns setof employees as $$
|
||||
select * from employees where supervisor_id = $1.id
|
||||
@@ -562,7 +562,7 @@ Recursive Many-To-One
|
||||
Let's take the same ``employees`` table from :ref:`recursive_o2m_embed`.
|
||||
To get the Many-To-One relationship, that is, the employees with their respective supervisor, you need to create a function like this one:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function supervisor(employees) returns setof employees rows 1 as $$
|
||||
select * from employees where id = $1.supervisor_id
|
||||
@@ -614,7 +614,7 @@ Recursive Many-To-Many
|
||||
|
||||
To get all the subscribers of a user as well as the ones they're following, define these functions:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function subscribers(users) returns setof users as $$
|
||||
select u.*
|
||||
@@ -756,7 +756,7 @@ If you have a :ref:`Stored Procedure <s_procs>` that returns a table type, you c
|
||||
|
||||
Here's a sample function (notice the ``RETURNS SETOF films``).
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE FUNCTION getallfilms() RETURNS SETOF films AS $$
|
||||
SELECT * FROM films;
|
||||
|
||||
@@ -88,7 +88,7 @@ To add schemas dynamically, you can use :ref:`in_db_config` plus :ref:`config re
|
||||
|
||||
- If the schemas' names have a pattern, like a ``tenant_`` prefix, do:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function postgrest.pre_config()
|
||||
returns void as $$
|
||||
@@ -100,7 +100,7 @@ To add schemas dynamically, you can use :ref:`in_db_config` plus :ref:`config re
|
||||
|
||||
- If there's no name pattern but they're created with a particular role (``CREATE SCHEMA mine AUTHORIZATION joe``), do:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create or replace function postgrest.pre_config()
|
||||
returns void as $$
|
||||
@@ -112,7 +112,7 @@ To add schemas dynamically, you can use :ref:`in_db_config` plus :ref:`config re
|
||||
|
||||
- Otherwise, you might need to create a table that stores the allowed schemas.
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
create table postgrest.config (schemas text);
|
||||
|
||||
@@ -125,7 +125,7 @@ To add schemas dynamically, you can use :ref:`in_db_config` plus :ref:`config re
|
||||
|
||||
Then each time you add an schema, do:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
NOTIFY pgrst, 'reload config';
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
|
||||
@@ -23,7 +23,7 @@ To supply arguments in an API call, include a JSON object in the request payload
|
||||
|
||||
For instance, assume we have created this function in the database.
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE FUNCTION add_them(a integer, b integer)
|
||||
RETURNS integer AS $$
|
||||
@@ -73,7 +73,7 @@ Functions with a single unnamed JSON parameter
|
||||
If you want the JSON request body to be sent as a single argument, you can create a function with a single unnamed ``json`` or ``jsonb`` parameter.
|
||||
For this the ``Content-Type: application/json`` header must be included in the request.
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE FUNCTION mult_them(json) RETURNS int AS $$
|
||||
SELECT ($1->>'x')::int * ($1->>'y')::int
|
||||
@@ -108,7 +108,7 @@ To send raw XML, the parameter type must be ``xml`` and the header ``Content-Typ
|
||||
|
||||
To send raw binary, the parameter type must be ``bytea`` and the header ``Content-Type: application/octet-stream`` must be included in the request.
|
||||
|
||||
.. code-block:: plpgsql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE TABLE files(blob bytea);
|
||||
|
||||
@@ -252,7 +252,7 @@ Let's get its :ref:`explain_plan` when calling it with filters applied:
|
||||
curl "http://localhost:3000/rpc/getallprojects?id=eq.1" \
|
||||
-H "Accept: application/vnd.pgrst.plan"
|
||||
|
||||
.. code-block:: psql
|
||||
.. code-block:: postgres
|
||||
|
||||
Aggregate (cost=8.18..8.20 rows=1 width=112)
|
||||
-> Index Scan using projects_pkey on projects (cost=0.15..8.17 rows=1 width=40)
|
||||
|
||||
@@ -88,7 +88,7 @@ any :code:`ANY` comparison matches any value in the list
|
||||
|
||||
For more complicated filters you will have to create a new view in the database, or use a stored procedure. For instance, here's a view to show "today's stories" including possibly older pinned stories:
|
||||
|
||||
.. code-block:: postgresql
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE VIEW fresh_stories AS
|
||||
SELECT *
|
||||
|
||||
Reference in New Issue
Block a user