From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mats Sjöberg <mats.sjoberg@cybernetics.se>
Cc: pgsql-sql@postgresql.org
Subject: Re: How do i extract a certain bit from a bigint column
Date: Wed, 12 May 2004 08:55:47 -0400
Message-ID: <24064.1084366547@sss.pgh.pa.us> (raw)
In-Reply-To: <A40C30932F52C4409B89ED049CCA06B13BA41D@srvex01.hk.cybernetics.se>
References: <A40C30932F52C4409B89ED049CCA06B13BA41D@srvex01.hk.cybernetics.se>
=?iso-8859-1?Q?Mats_Sj=F6berg?= <mats.sjoberg@cybernetics.se> 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
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: tgl@sss.pgh.pa.us, mats.sjoberg@cybernetics.se
Subject: Re: How do i extract a certain bit from a bigint column
In-Reply-To: <24064.1084366547@sss.pgh.pa.us>
* 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