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 35041D1DB81 for ; Wed, 12 May 2004 09:56:06 -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 44835-04 for ; Wed, 12 May 2004 09:55:48 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id CB3B2D1E206 for ; Wed, 12 May 2004 09:55:44 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i4CCtlvS024065; Wed, 12 May 2004 08:55:47 -0400 (EDT) To: =?iso-8859-1?Q?Mats_Sj=F6berg?= Cc: pgsql-sql@postgresql.org Subject: Re: How do i extract a certain bit from a bigint column In-reply-to: References: Comments: In-reply-to =?iso-8859-1?Q?Mats_Sj=F6berg?= message dated "Wed, 12 May 2004 13:05:09 +0200" Date: Wed, 12 May 2004 08:55:47 -0400 Message-ID: <24064.1084366547@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/106 X-Sequence-Number: 17820 =?iso-8859-1?Q?Mats_Sj=F6berg?= writes: > What is the syntax to extract those bits? At least in 7.4, you can do it the same way you'd do it in C: regression=# select ((47::bigint) >> 3) & 1; ?column? ---------- 1 (1 row) I'm not sure when the bigint >> and & operators got added, but \do would tell you quickly enough if they're in your version. Mind you that this is not going to be an especially fast solution, since these are not indexable operators. You might be better advised to rethink your data representation. regards, tom lane