Hi, > When we add such casts between bytea and the integer/numeric types, > one of the problems mentioned the first of the thread, that is, > "we don't have a convenient way of casting a bytea to an integer / bigint > and vice versa", would seem be resolved. > > On the other hand, I suppose get_bytes() and set_bytes() are still useful > for extracting bytes from byteas, etc. If casting is no longer the main > purpose of these functions, are variations that get_bytes returns bytea > instead of bigint, and set_bytes receives bytea as the newvalue argument > useful? I wonder it would eliminate the restrict that size cannot be larger > than 8.
No, casting between bytea and numeric will not replace get_bytes() / set_bytes() for performance reasons. Consider the case when you want to extract an int4 from a bytea. get_bytes() is going to be very fast while substr() -> ::numeric -> ::integer chain will require unnecessary copying and conversions. Casting between bytea and numeric is only useful when one has to deal with integers larger than 8 bytes. Whether this happens often is a debatable question. > Here are my very trivial comments on the patch. > > + * this routine treats "bytea" as an array of bytes. > > Maybe, the sentence should start with "This ... ". > > + while(size) > + { > > I wonder inserting a space after "while" is the standard style. Thanks, fixed. -- Best regards, Aleksander Alekseev
v2-0001-Add-get_bytes-and-set_bytes-functions.patch
Description: Binary data