Skip site navigation (1) Skip section navigation (2)

Re: How do i extract a certain bit from a bigint column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mats Sjöberg <mats(dot)sjoberg(at)cybernetics(dot)se>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How do i extract a certain bit from a bigint column
Date: 2004-05-12 12:55:47
Message-ID: 24064.1084366547@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
=?iso-8859-1?Q?Mats_Sj=F6berg?= <mats(dot)sjoberg(at)cybernetics(dot)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

In response to

pgsql-sql by date

Next:From: scott.marloweDate: 2004-05-12 13:59:10
Subject: Re: working with schema
Previous:From: Mike RylanderDate: 2004-05-12 12:17:39
Subject: Re: How do i extract a certain bit from a bigint column

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group