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

Commit

Permalink
fix: any media type should be bytea
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Dec 5, 2023
1 parent 48dee75 commit 8fd4fa0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/references/api/media_type_handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Let's define an any handler for a view that will always respond with ``XML`` out

.. code-block:: postgres
create domain "*/*" as pg_catalog.xml;
create domain "*/*" as bytea;
-- we'll use an .xml suffix for the view to be clear its output is always XML
create view "lines.xml" as
Expand All @@ -230,7 +230,7 @@ Let's define an any handler for a view that will always respond with ``XML`` out
-- transition function
create or replace function lines_xml_trans (state "*/*", next "lines.xml")
returns "*/*" as $$
select xmlconcat(state, xmlelement(name line, xmlattributes(next.id as id, next.name as name), next.geom));
select state || xmlelement(name line, xmlattributes(next.id as id, next.name as name), next.geom)::text::bytea || E'\n' ;
$$ language sql;
-- final function
Expand Down Expand Up @@ -258,6 +258,16 @@ Let's define an any handler for a view that will always respond with ``XML`` out
, finalfunc = lines_xml_final
);
Test it on SQL:

.. code-block:: psql
select (encode(lines_xml_agg(x), 'escape'))::xml from "lines.xml" x;
encode
------------------------------------------------------------------------------------------------------------------------------
<line id="1" name="line-1">0102000020E610000002000000000000000000F03F000000000000F03F00000000000014400000000000001440</line>+
<line id="2" name="line-2">0102000020E6100000020000000000000000000040000000000000004000000000000018400000000000001840</line>+
Now we can omit the ``Accept`` header and it will respond with XML.

.. code-block:: bash
Expand Down

0 comments on commit 8fd4fa0

Please sign in to comment.