I have a requirement that needs to store lots of bits and it's actually a time setting for every 15 minutes in a week (indicating if a user is free during that time).
So for one day we need:
60 minutes/ 15 = 4 * 24 hours = 96 bit
And for a week, it will be:
96 * 7 = 672
I was originally thinking that I could store this in 7 columns of
each column representing a day and the first bigint of the array represening the bit from
00:00 to 12:00 (12 * 4 = 48bit).
And here is how I calculate the bigint:
start_idx := extract(EPOCH FROM (first_half::time - '00:00'::time))::integer/60/15; end_idx := extract(EPOCH FROM (first_half::time - '00:00'::time))::integer/60/15; -- RAISE NOTICE 'idx % %', start_idx, end_idx; WHILE start_idx < end_idx LOOP first_r := first_r | (1::bigint << start_idx); start_idx = start_idx + 1; END LOOP;
start_idx will be the result and contains all the bits from
00:00 to 12:00.
But this is ugly because I have to separate the time setting into two parts and I just come across this thread that says that I should store the bits separately.
So I am not sure if I should use the array or if I should just create
672 columns of Boolean which I think is a bit crazy!