bitwise storage and operations

From: Jonathan Vanasco <postgres(at)2xlp(dot)com>
To: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: bitwise storage and operations
Date: 2016-09-26 20:44:34
Message-ID: 2B9ADEA9-3B77-4F74-9D49-56B39FEB0DFB@2xlp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


We've been storing some "enumerated"/"set" data in postgresql as INT or BIT(32) for several years for some flags/toggles on records.

This was preferable for storage to the ENUM type (or multiple columns), as we often changed the number of enumerated options or their labels -- and computing everything in the application saved the trouble of database migrations. This has worked out perfectly -- until today.

For the first time ever, we need to run some queries that filter on these columns at the PostgreSQL level -- and I can't figure out how.

The documentation doesn't have any examples for SELECT for the bitwise operators, and everything I've found on various threads/forums has addressed inserts or converting on a select -- but never a comparison.

I've tried numerous forms and have gotten as far as CASTing everything to BIT(n), but I can't seem to construct a valid query that can filter what I want.

Can anyone share a sample WHERE clause or two that does a bitwise comparison against an INT or BIT column?

Thanks!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-09-26 21:04:28 Re: bitwise storage and operations
Previous Message Kevin Grittner 2016-09-26 20:34:43 Re: Incrementally refreshed materialized view