X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A5079D1D73D for ; Wed, 12 May 2004 09:25:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 37722-05 for ; Wed, 12 May 2004 09:25:15 -0300 (ADT) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by svr1.postgresql.org (Postfix) with ESMTP id 3E757D1E18E for ; Wed, 12 May 2004 09:25:06 -0300 (ADT) Received: from squeegy.miker.net (c-24-131-54-180.mw.client2.attbi.com[24.131.54.180]) by comcast.net (rwcrmhc12) with ESMTP id <2004051212250501400jjmcne>; Wed, 12 May 2004 12:25:05 +0000 From: Mike Rylander To: Subject: Re: How do i extract a certain bit from a bigint column Date: Wed, 12 May 2004 08:17:39 -0400 User-Agent: KMail/1.6.1 References: In-Reply-To: Cc: Mats =?iso-8859-1?q?Sj=F6berg?= MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200405120817.39593.miker@purplefrog.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200405/105 X-Sequence-Number: 17819 On Wednesday 12 May 2004 07:05 am, Mats Sj=F6berg wrote: > Hello everyone > In a table i have a column status of type bigint. > I need to create a view of the table including all rows with bit 4 set > (value 8). > At the same time i need to exclude excludig all rows with bit 2 set. > > What is the syntax to extract those bits? > I have tested get_bit(string, offset) but this requires a string, and not= a > bigint. > Is there a function to The easiest way is to test for a bit using bitwise and: SELECT * FROM table WHERE (status & 2::BIGINT) <> 0 AND (status & 8::BIGINT= ) =3D=20 0; -miker