pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aditya <aditya@grot.org>
To: pgsql-sql@postgresql.org
Subject: converting from bigint to bit to use bitwise operators
Date: Mon, 21 Apr 2003 14:50:20 -0700
Message-ID: <20030421215020.GA71612@mighty.grot.org> (raw)
In-Reply-To: <20030418191128.89A67476363@postgresql.org>
References: <20030418191128.89A67476363@postgresql.org>

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




view thread (3+ messages)  latest in thread

Message-ID: <20030421215020.GA71612@mighty.grot.org>
Permalink:  ../20030421215020.GA71612@mighty.grot.org/
Also on:    postgresql.org/message-id/20030421215020.GA71612@mighty.grot.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: aditya@grot.org
  Subject: Re: converting from bigint to bit to use bitwise operators
  In-Reply-To: <20030421215020.GA71612@mighty.grot.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox