diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index 0ae9d7b..c709906 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -2051,3 +2051,20 @@ jsonb_float8(PG_FUNCTION_ARGS) PG_RETURN_DATUM(retValue); } + +/* + * send jsonb as bytea in the format: + * uint8 version number, then a string of bytes (in the on-disk format) +*/ +Datum +jsonb_raw_bytes(PG_FUNCTION_ARGS) +{ + Jsonb *jb = PG_GETARG_JSONB_P(0); + StringInfoData buf; + pq_begintypsend(&buf); + int version = 1; + pq_sendint8(&buf, version); + pq_sendbytes(&buf, VARDATA(jb), VARSIZE_ANY_EXHDR(jb)); + + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index a146510..a90df9d 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -4391,6 +4391,9 @@ { oid => '2580', descr => 'convert jsonb to float8', proname => 'float8', prorettype => 'float8', proargtypes => 'jsonb', prosrc => 'jsonb_float8' }, +{ oid => '4142', descr => 'convert jsonb to raw bytes', + proname => 'jsonb_raw_bytes', prorettype => 'bytea', proargtypes => 'jsonb', + prosrc => 'jsonb_raw_bytes' } # formatting { oid => '1770', descr => 'format timestamp with time zone to text',