pgsql: Allow casting between bytea and integer types.

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow casting between bytea and integer types.
Date: 2025-03-07 09:35:16
Message-ID: E1tqU6u-001EVK-2A@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow casting between bytea and integer types.

This allows smallint, integer, and bigint values to be cast to and
from bytea. The bytea value is the two's complement representation of
the integer, with the most significant byte first. For example:

1234::bytea -> \x000004d2
(-1234)::bytea -> \xfffffb2e

Author: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Reviewed-by: Joel Jacobson <joel(at)compiler(dot)org>
Reviewed-by: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Reviewed-by: Peter Eisentraut <peter(at)eisentraut(dot)org>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAJ7c6TPtOp6%2BkFX5QX3fH1SVr7v65uHr-7yEJ%3DGMGQi5uhGtcA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6da469badaffec32f8a804181cca279561467378

Modified Files
--------------
doc/src/sgml/func.sgml | 17 ++++++
src/backend/utils/adt/varlena.c | 96 +++++++++++++++++++++++++++++
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_cast.dat | 14 +++++
src/include/catalog/pg_proc.dat | 19 ++++++
src/test/regress/expected/opr_sanity.out | 3 +
src/test/regress/expected/strings.out | 102 +++++++++++++++++++++++++++++++
src/test/regress/sql/strings.sql | 29 +++++++++
8 files changed, 281 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-03-07 10:57:22 pgsql: Improve possible performance regression
Previous Message Michael Paquier 2025-03-07 07:40:17 Re: pgsql: Make postgres_fdw's query_cancel test less flaky.