Is there any way to create an exponential sequence rather than incremental?
What I would like is a sequence that would start at 1 and grow exponentially
by 2. (i.e. 1,2,4,8,16,32....)
The advantages are, IMHO, obvious:
With a sequence "my_seq" declared as above create a table as follows:
create table example
(
"ID" int4 DEFAULT nextval('"my_seq"'::text) NOT NULL,
"description" varchar(32),
CONSTRAINT "example_pkey" PRIMARY KEY ("ID")
);
CREATE UNIQUE INDEX "example_description" ON "example" ("description");
When referenced by another table with a 1:many relationship, instead of
using a third table, the values can be stored in a single field using a sum
of the "ID"s and reference can be queried using a logical AND. Assuming the
referring table "example2" contains a field "example" which references the
above table with the pk on "example2" being "e2id":
select "description" from "example", "example2" where ("ID" & "example")!=0
and "e2id"=555;
Am I nuts? This seems so obvious but I've never seen it applied anywhere.
Of course, I'm by no means a db guru.
Of course, if I can't do it with a sequence, I could write a function....