X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BFFD4475D3B for ; Mon, 21 Apr 2003 17:50:20 -0400 (EDT) Received: from mighty.grot.org (66-117-150-96.web.lmi.net [66.117.150.96]) by postgresql.org (Postfix) with ESMTP id D409D475B47 for ; Mon, 21 Apr 2003 17:50:18 -0400 (EDT) Received: by mighty.grot.org (Postfix, from userid 515) id BE5835D26; Mon, 21 Apr 2003 14:50:20 -0700 (PDT) Date: Mon, 21 Apr 2003 14:50:20 -0700 From: Aditya To: pgsql-sql@postgresql.org Subject: converting from bigint to bit to use bitwise operators Message-ID: <20030421215020.GA71612@mighty.grot.org> References: <20030418191128.89A67476363@postgresql.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030418191128.89A67476363@postgresql.org> X-Spam-Status: No, hits=-12.8 required=5.0 tests=BAYES_20,IN_REP_TO,REFERENCES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/311 X-Sequence-Number: 13012 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