Re: convert int to bytea - Mailing list pgsql-hackers

From Usama Dar
Subject Re: convert int to bytea
Date
Msg-id ff0e67090711290841n413b2748ta2b4209184f8d32e@mail.gmail.com
Whole thread Raw
In response to Re: convert int to bytea  (Zoltan Boszormenyi <zb@cybertec.at>)
Responses Re: convert int to bytea  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers


On Nov 29, 2007 9:35 PM, Zoltan Boszormenyi <zb@cybertec.at> wrote:
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@mcnaught.org
> <mailto:doug@mcnaught.org>> wrote:
>
>     On 11/29/07, ohp@pyrenet.fr <mailto:ohp@pyrenet.fr>
>     <ohp@pyrenet.fr <mailto:ohp@pyrenet.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.

1) i wasn't aware people are sensitive  to top email reply vs inline, apologies if it offended you

2) i know what a byte order is , i just thought your interface i.e. libpq would convert it to the local byte  order.


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





--
Usama Munir Dar http://linkedin.com/in/usamadar
Consultant Architect
Cell:+92 321 5020666
Skype: usamadar

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pgwin32_open returning EINVAL
Next
From: Magnus Hagander
Date:
Subject: Re: Re: pgsql: New versions of mingw have gettimeofday(), so add an autoconf