

\set ECHO all
\copy (select '{"foo": "bar"}') to '/tmp/raw_test.jsonb' (format raw);

create temporary table raw_byte (b bytea);
create temporary table raw_text (t text);

\copy raw_jsonb from '/tmp/raw_test.blob' (format raw);

\copy raw_byte from '/tmp/raw_test.blob' (format raw);

select encode(b,'escape')::text::json from raw_byte;

\copy raw_text from '/tmp/raw_test.blob' (format raw);

select t::jsonb from raw_text;

create temporary table binary_byte (b bytea);
create temporary table binary_text (t text);

\copy binary_byte from '/tmp/raw_test.blob' (format binary);

select encode(b,'escape')::jsonb from binary_byte;

\copy binary_text from '/tmp/raw_test.blob' (format binary);

select t::jsonb from binary_text;

