mirror of
https://github.com/postgres/postgres.git
synced 2026-01-27 21:43:08 +03:00
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@timescale.com> Reviewed-by: Joel Jacobson <joel@compiler.org> Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAJ7c6TPtOp6%2BkFX5QX3fH1SVr7v65uHr-7yEJ%3DGMGQi5uhGtcA%40mail.gmail.com
This commit is contained in:
@@ -57,6 +57,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 202503031
|
||||
#define CATALOG_VERSION_NO 202503071
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,6 +320,20 @@
|
||||
{ castsource => 'varchar', casttarget => 'name', castfunc => 'name(varchar)',
|
||||
castcontext => 'i', castmethod => 'f' },
|
||||
|
||||
# Allow explicit coercions between bytea and integer types
|
||||
{ castsource => 'int2', casttarget => 'bytea', castfunc => 'bytea(int2)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
{ castsource => 'int4', casttarget => 'bytea', castfunc => 'bytea(int4)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
{ castsource => 'int8', casttarget => 'bytea', castfunc => 'bytea(int8)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
{ castsource => 'bytea', casttarget => 'int2', castfunc => 'int2(bytea)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
{ castsource => 'bytea', casttarget => 'int4', castfunc => 'int4(bytea)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
{ castsource => 'bytea', casttarget => 'int8', castfunc => 'int8(bytea)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
|
||||
# Allow explicit coercions between int4 and "char"
|
||||
{ castsource => 'char', casttarget => 'int4', castfunc => 'int4(char)',
|
||||
castcontext => 'e', castmethod => 'f' },
|
||||
|
||||
@@ -1165,6 +1165,25 @@
|
||||
proname => 'name', proleakproof => 't', prorettype => 'name',
|
||||
proargtypes => 'bpchar', prosrc => 'bpchar_name' },
|
||||
|
||||
{ oid => '8577', descr => 'convert int2 to bytea',
|
||||
proname => 'bytea', proleakproof => 't', prorettype => 'bytea',
|
||||
proargtypes => 'int2', prosrc => 'int2_bytea' },
|
||||
{ oid => '8578', descr => 'convert int4 to bytea',
|
||||
proname => 'bytea', proleakproof => 't', prorettype => 'bytea',
|
||||
proargtypes => 'int4', prosrc => 'int4_bytea' },
|
||||
{ oid => '8579', descr => 'convert int8 to bytea',
|
||||
proname => 'bytea', proleakproof => 't', prorettype => 'bytea',
|
||||
proargtypes => 'int8', prosrc => 'int8_bytea' },
|
||||
{ oid => '8580', descr => 'convert bytea to int2',
|
||||
proname => 'int2', prorettype => 'int2',
|
||||
proargtypes => 'bytea', prosrc => 'bytea_int2' },
|
||||
{ oid => '8581', descr => 'convert bytea to int4',
|
||||
proname => 'int4', prorettype => 'int4',
|
||||
proargtypes => 'bytea', prosrc => 'bytea_int4' },
|
||||
{ oid => '8582', descr => 'convert bytea to int8',
|
||||
proname => 'int8', prorettype => 'int8',
|
||||
proargtypes => 'bytea', prosrc => 'bytea_int8' },
|
||||
|
||||
{ oid => '449', descr => 'hash',
|
||||
proname => 'hashint2', prorettype => 'int4', proargtypes => 'int2',
|
||||
prosrc => 'hashint2' },
|
||||
|
||||
Reference in New Issue
Block a user