converting from bigint to bit to use bitwise operators

From: Aditya <aditya(at)grot(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: converting from bigint to bit to use bitwise operators
Date: 2003-04-21 21:50:20
Message-ID: 20030421215020.GA71612@mighty.grot.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

For historical reasons, I have IPv4 addresses stored as bigint and I would
like to convert them to dot-quad (ie. A.B.C.D) in a select. This is how I
would normally do it (the remotehost column is the IP address as a bigint):

select
((remotehost::bit varying(32) >> 24) & 11111111) || '.' ||
((remotehost::bit varying(32) & 11111100) >> 16) || '.' ||
((remotehost::bit varying(32) & 11110000) >> 8) || '.' ||
((remotehost::bit varying(32) & 11000000)) as ip,
httpquery
from
weblogs
;

however this complains:

ERROR: Cannot cast type 'bigint' to 'bit varying'

hints?

Thanks,
Adi

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Randall Lucas 2003-04-21 21:55:14 Re: converting from bigint to bit to use bitwise operators
Previous Message Randall Lucas 2003-04-21 21:46:36 Re: PROBLEM WITH FUNCTIONS