Re: converting from bytea to integers

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: converting from bytea to integers
Date: 2009-04-20 21:23:34
Message-ID: 22aeb499-b1bc-4ec9-9f3b-b9323ea27f92@mm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John DeSoi wrote:

> I'd like to convert some bytea data to an array of four byte integers

> (and vice versa). I'm probably missing something obvious, but I don't

> see an efficient way to generate a 4 byte integer from a bytea string

> (could be big endian or little endian).

get_byte()?

mailtest=> \set e '\'\12\15\107\20\'::bytea'

mailtest=> select
get_byte(:e,0),get_byte(:e,1),get_byte(:e,2),get_byte(:e,3);
get_byte | get_byte | get_byte | get_byte
----------+----------+----------+----------
10 | 13 | 71 | 16
(1 row)

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2009-04-20 21:51:18 Re: Postgresql 8.3X supports Arrays of Composite Types?
Previous Message Robert Morton 2009-04-20 21:21:31 round behavior differs between 8.1.5 and 8.3.7