Subject | Feature request : Generator tables |
---|---|
Author | Jonathan Neve |
Post date | 2004-02-20T07:43:12Z |
Hi!
Generators are nice. The main thing that's good about them is that
they're transaction independant. Thus, they are perfect for generating a
sequence of consecutive interger values. However, it's difficult to use
a generator as a primary key in many cases, because it is not related to
anything : it's just a sequence of numbers. Many of my customers ask for
invoice numbering that includes that year and month of the invoice, and,
within each month, an independant counter, like this : "YYMM0001". So
for such situations, it's more difficult to generate a corrrect PK value.
The solution would be to use a table with one counter per year/month,
and to simply increment this counter. However, this approach has the big
disadvantage that it's dependant on the transaction's view of the table,
which can obviously cause problems.
So what I would like to suggest would be a solution similar to
generators, but allowing to have a variable number of independant
counters, which could then be accessed like a hash table.
Something like this:
CREATE HASH_GENERATOR GEN_TABLE_A;
SELECT HASH_GEN_ID(GEN_TABLE_A, 'YYMM', 1) FROM RDB$DATABASE;
What do you think?
Thanks!
Jonathan Neve.
Generators are nice. The main thing that's good about them is that
they're transaction independant. Thus, they are perfect for generating a
sequence of consecutive interger values. However, it's difficult to use
a generator as a primary key in many cases, because it is not related to
anything : it's just a sequence of numbers. Many of my customers ask for
invoice numbering that includes that year and month of the invoice, and,
within each month, an independant counter, like this : "YYMM0001". So
for such situations, it's more difficult to generate a corrrect PK value.
The solution would be to use a table with one counter per year/month,
and to simply increment this counter. However, this approach has the big
disadvantage that it's dependant on the transaction's view of the table,
which can obviously cause problems.
So what I would like to suggest would be a solution similar to
generators, but allowing to have a variable number of independant
counters, which could then be accessed like a hash table.
Something like this:
CREATE HASH_GENERATOR GEN_TABLE_A;
SELECT HASH_GEN_ID(GEN_TABLE_A, 'YYMM', 1) FROM RDB$DATABASE;
What do you think?
Thanks!
Jonathan Neve.