| From: | Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it> |
|---|---|
| To: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Converting BYTEA from/to BIGINT |
| Date: | 2010-07-26 10:03:45 |
| Message-ID: | AANLkTinDPCrfmjU5oHvNSDZU8NC4gYwY932bcWy02+4H@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
2010/7/26 Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>:
> Hi all.
>
> I'd like to convert an 8-bytes BYTEA into a BIGINT and possibly vice versa.
> Is there any way to do it?
Something like:
CREATE OR REPLACE FUNCTION bytea_to_int8( ba BYTEA, OUT res INT8 )
LANGUAGE plpgsql STRICT
AS $BODY$
DECLARE
i INT;
BEGIN
res := 0;
FOR i IN 0 .. 7 LOOP
res := 256*res + get_byte( ba,i );
END LOOP;
END;
$BODY$;
gives me back errors (ERROR: bigint out of range) because of overflow
at step no.7
--
Vincenzo Romano
NotOrAnd Information Technologies
NON QVIETIS MARIBVS NAVTA PERITVS
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Vincenzo Romano | 2010-07-26 10:04:26 | Re: Converting BYTEA from/to BIGINT |
| Previous Message | Pavel Stehule | 2010-07-26 09:47:22 | Re: Converting BYTEA from/to BIGINT |