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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user