pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
converting from bigint to bit to use bitwise operators
3+ messages / 2 participants
[nested] [flat]

* converting from bigint to bit to use bitwise operators
@ 2003-04-18 19:11  Aditya <aditya@grot.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Aditya @ 2003-04-18 19:11 UTC (permalink / raw)
  To: 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:

- remotehost 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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* converting from bigint to bit to use bitwise operators
@ 2003-04-21 21:50  Aditya <aditya@grot.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Aditya @ 2003-04-21 21:50 UTC (permalink / raw)
  To: 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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: converting from bigint to bit to use bitwise operators
@ 2003-04-21 21:55  Randall Lucas <rlucas@tercent.net>
  parent: Aditya <aditya@grot.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Randall Lucas @ 2003-04-21 21:55 UTC (permalink / raw)
  To: Aditya <aditya@grot.org>; +Cc: pgsql-sql


Adi,

Try an explicit cast into a text type and then into a bit string type.

Best,

Randall

On Monday, April 21, 2003, at 05:50 PM, Aditya wrote:

> 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
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2003-04-21 21:55 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-18 19:11 converting from bigint to bit to use bitwise operators Aditya <aditya@grot.org>
2003-04-21 21:50 converting from bigint to bit to use bitwise operators Aditya <aditya@grot.org>
2003-04-21 21:55 ` Randall Lucas <rlucas@tercent.net>

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