Bit-wise foreign keys

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Postgres-General General <pgsql-general(at)postgresql(dot)org>
Subject: Bit-wise foreign keys
Date: 2010-09-20 17:06:15
Message-ID: F9331D12-DD94-4A5E-81CC-A1AED3676058@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey all,

I'm tossing an idea around again, namely using bit positions and values as foreign key references. Let's start with a bit of background information:

I'm currently parsing a log-file that I want to apply all kinds of statistical analysis to. This file contains lines of records of data, among which are some bytes of which each bit marks a certain truth-value. As an internal data-object that's just dandy, but presenting it to, for example a user, or to query it for certain masks without having to delve into the definition of that particular bit-field it would be great to have a textual representation of each bit.

Let's say we have this byte, with the attached meanings:
pos meaning
0 RED (least significant bit)
1 GREEN
2 BLUE
3 FIRE
4 WATER
5 EARTH
7 AIR (most significant bit)

Now if I see a value of 0x05, I know that this corresponds to [RED, FIRE] and if I have a value of 0x41 I know that I'm in trouble as there's a bit set that has no meaning!

Reeks of a foreign key constraint, doesn't it? An odd one though, as one value can contain multiple bits and thus references multiple foreign values...

Do we have anything for this yet? If not, would this be a good feature?
I imagine something similar could be done for (fixed-length?) arrays too...

Of course something like this would benefit from some convenience functions; you wouldn't really want to get multiple records for the same row with different bits matched - something like bit_accum() to turn the separate results into an array would be useful I think.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4c97949110251883445726!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2010-09-20 17:25:23 Re: Bit-wise foreign keys
Previous Message Dmitriy Igrishin 2010-09-20 17:04:08 Re: Data directory permissions.