Следующее даст вам справочную таблицу со всем представлением, которое вы искали. Вы можете присоединиться к этому.
begin;
CREATE TABLE LookUpHours(ID integer primary key, representation text);
insert into LookUpHours (id) values ( 0);
insert into LookUpHours (id) values ( 1);
insert into LookUpHours (id) values ( 2);
insert into LookUpHours (id) values ( 3);
insert into LookUpHours (id) values ( 4);
insert into LookUpHours (id) values ( 5);
insert into LookUpHours (id) values ( 6);
insert into LookUpHours (id) values ( 7);
insert into LookUpHours (id) values ( 8);
insert into LookUpHours (id) values ( 9);
insert into LookUpHours (id) values (10);
insert into LookUpHours (id) values (11);
insert into LookUpHours (id) values (12);
insert into LookUpHours (id) values (13);
insert into LookUpHours (id) values (14);
insert into LookUpHours (id) values (15);
insert into LookUpHours (id) values (16);
insert into LookUpHours (id) values (17);
insert into LookUpHours (id) values (18);
insert into LookUpHours (id) values (19);
insert into LookUpHours (id) values (20);
insert into LookUpHours (id) values (21);
insert into LookUpHours (id) values (22);
insert into LookUpHours (id) values (23);
insert into LookUpHours (id) values (24);
insert into LookUpHours (id) values (25);
insert into LookUpHours (id) values (26);
insert into LookUpHours (id) values (27);
insert into LookUpHours (id) values (28);
insert into LookUpHours (id) values (29);
insert into LookUpHours (id) values (30);
insert into LookUpHours (id) values (31);
update LookUpHours set representation =
case when (id & 16) != 0 then '1' else '0' end ||
case when (id & 8) != 0 then '1' else '0' end ||
case when (id & 4) != 0 then '1' else '0' end ||
case when (id & 2) != 0 then '1' else '0' end ||
case when (id & 1) != 0 then '1' else '0' end
;
commit;
Таблица результатов содержит следующие данные:
ID representation
---------- --------------
0 00000
1 00001
2 00010
3 00011
4 00100
5 00101
6 00110
7 00111
8 01000
9 01001
10 01010
11 01011
12 01100
13 01101
14 01110
15 01111
16 10000
17 10001
18 10010
19 10011
20 10100
21 10101
22 10110
23 10111
24 11000
25 11001
26 11010
27 11011
28 11100
29 11101
30 11110
31 11111