Skip site navigation (1) Skip section navigation (2)

Re: convert int to bytea

From: Zoltan Boszormenyi <zb(at)cybertec(dot)at>
To: Usama Dar <munir(dot)usama(at)gmail(dot)com>
Cc: Douglas McNaught <doug(at)mcnaught(dot)org>, ohp(at)pyrenet(dot)fr, Gregory Stark <stark(at)enterprisedb(dot)com>, pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: convert int to bytea
Date: 2007-11-29 16:35:31
Message-ID: 474EEA53.1070908@cybertec.at (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi,

please don't top post to someone who didn't used this convention
in answering you. It's impolite. I edited the mail a bit to return sanity.

> On Nov 29, 2007 9:00 PM, Douglas McNaught <doug(at)mcnaught(dot)org 
> <mailto:doug(at)mcnaught(dot)org>> wrote:
>
>     On 11/29/07, ohp(at)pyrenet(dot)fr <mailto:ohp(at)pyrenet(dot)fr>
>     <ohp(at)pyrenet(dot)fr <mailto:ohp(at)pyrenet(dot)fr>> wrote:
>
>     > On Thu, 29 Nov 2007, Gregory Stark wrote:
>     >
>     > > What do you want the resulting bytea to look like?
>     > >
>     > example : id = 9 , bytea = '\000\000\011' IIRC
>
>     What do you expect to happen when server and client are
>     differently-endian?
>
>     -Doug
>

Usama Dar írta:
 > Does it matter if you have written an explicit cast for int to bytea?
 >

You don't know what't endianness is, do you?
Say, you have a number: 0x12345678.
This is stored differently depending on the endianness.

Big-endian (like Sparc, Motorola, etc):
0x12 0x34 0x56 0x78

Little-endian (Intel-compatibles, etc):
0x78 0x56 0x34 0x12

So, how do you want your number to come out as a byte array?
Since a bytea is a sequence of bytes as stored in memory,
you may have different meaning for an int->bytea conversion.

It's your homework to look up what's "network order" is. :-)
But it would give you consistent answer no matter
what CPU your server uses.

-- 
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/



In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2007-11-29 16:36:00
Subject: Re: pgwin32_open returning EINVAL
Previous:From: Gregory StarkDate: 2007-11-29 16:29:41
Subject: Re: Time to update list of contributors

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group