1

is it possible in PostgreSQL 8.4 to concat multiple integers (int4) values to a bytea value?

For example:

5::int4 || 1::int4

should result in a bytea value with (0x05 0x00 0x00 0x00 0x01 0x00 0x00 0x00), assuming a little endian machine.

2 Answers 2

2

Well, int4send will convert an int4 to a bytea, but I suspect from the name it will always use network ordering.

that is:

steve@steve@[local] =# select int4send(3);
  int4send  
------------
 \x00000003

event on an amd64 machine.

Sign up to request clarification or add additional context in comments.

1 Comment

You might mention that the *send() functions are (still) undocumented!
1

An indirect conversion can be made with select byteain(bit_out(5::bit(32) || 1::bit(32))) or select int4send(5)||int4send(1) which results in 0000000000000000000000000000010100000000000000000000000000000001.

You could also use binary string functions to convert to your desired encoding. See Maarten Foqué's answer on the pgsql-general list for a solution to a similar problem. You should be able to simple concatenate the resulting bytea values from his function or a similar function (but mark it as stable instead of volatile).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.