mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +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.
|
||||
|
@ -57,6 +57,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 202503111
|
||||
#define CATALOG_VERSION_NO 202503131
|
||||
|
||||
#endif
|
||||
|
@ -1518,6 +1518,9 @@
|
||||
{ oid => '6163', descr => 'number of set bits',
|
||||
proname => 'bit_count', prorettype => 'int8', proargtypes => 'bytea',
|
||||
prosrc => 'bytea_bit_count' },
|
||||
{ oid => '8694', descr => 'reverse bytea',
|
||||
proname => 'reverse', prorettype => 'bytea', proargtypes => 'bytea',
|
||||
prosrc => 'bytea_reverse' },
|
||||
|
||||
{ oid => '725',
|
||||
proname => 'dist_pl', prorettype => 'float8', proargtypes => 'point line',
|
||||
|
@ -236,6 +236,24 @@ SELECT E'De\\678dBeEf'::bytea;
|
||||
ERROR: invalid input syntax for type bytea
|
||||
LINE 1: SELECT E'De\\678dBeEf'::bytea;
|
||||
^
|
||||
SELECT reverse(''::bytea);
|
||||
reverse
|
||||
---------
|
||||
\x
|
||||
(1 row)
|
||||
|
||||
SELECT reverse('\xaa'::bytea);
|
||||
reverse
|
||||
---------
|
||||
\xaa
|
||||
(1 row)
|
||||
|
||||
SELECT reverse('\xabcd'::bytea);
|
||||
reverse
|
||||
---------
|
||||
\xcdab
|
||||
(1 row)
|
||||
|
||||
SET bytea_output TO escape;
|
||||
SELECT E'\\xDeAdBeEf'::bytea;
|
||||
bytea
|
||||
|
@ -77,6 +77,10 @@ SELECT E'De\123dBeEf'::bytea;
|
||||
SELECT E'De\\123dBeEf'::bytea;
|
||||
SELECT E'De\\678dBeEf'::bytea;
|
||||
|
||||
SELECT reverse(''::bytea);
|
||||
SELECT reverse('\xaa'::bytea);
|
||||
SELECT reverse('\xabcd'::bytea);
|
||||
|
||||
SET bytea_output TO escape;
|
||||
SELECT E'\\xDeAdBeEf'::bytea;
|
||||
SELECT E'\\x De Ad Be Ef '::bytea;
|
||||
|
Reference in New Issue
Block a user