1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Add reverse(bytea).

This commit introduces a function for reversing the order of the
bytes in binary strings.

Bumps catversion.

Author: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://postgr.es/m/CAJ7c6TMe0QVRuNssUArbMi0bJJK32%2BzNA3at5m3osrBQ25MHuw%40mail.gmail.com
This commit is contained in:
Nathan Bossart
2025-03-13 11:20:53 -05:00
parent bb25276205
commit 0697b23906
6 changed files with 64 additions and 1 deletions

View File

@@ -3398,6 +3398,27 @@ byteaSetBit(PG_FUNCTION_ARGS)
PG_RETURN_BYTEA_P(res);
}
/*
* Return reversed bytea
*/
Datum
bytea_reverse(PG_FUNCTION_ARGS)
{
bytea *v = PG_GETARG_BYTEA_PP(0);
const char *p = VARDATA_ANY(v);
int len = VARSIZE_ANY_EXHDR(v);
const char *endp = p + len;
bytea *result = palloc(len + VARHDRSZ);
char *dst = (char *) VARDATA(result) + len;
SET_VARSIZE(result, len + VARHDRSZ);
while (p < endp)
*(--dst) = *p++;
PG_RETURN_BYTEA_P(result);
}
/* text_name()
* Converts a text type to a Name type.