Subject | Re: [firebird-support] SELECT MAX() or Generator |
---|---|
Author | Ann W. Harrison |
Post date | 2005-12-15T20:40:15Z |
William L. Thomson Jr. wrote:
be addressed by putting a descending index on NUM. The second is that
it flat doesn't work multi-user, which may or may not be important to
you. If you absolutely must have sequential numbers, follow Alexandre
Benson Smith's suggestion, but be aware that any mechanism that produces
reliably sequential numbers will serialize updates.
Regards,
Ann
>There are two problems with this. The first is performance, which can
> DECLARE VARIABLE max_num INTEGER;
> BEGIN
> IF(new.NUM is NULL)
> THEN
> BEGIN
> SELECT MAX(NUM) FROM MY_TABLE INTO max_num;
> new.NUM = max_num+1;
> END
> END
>
> I have been doing this for quite some time.
be addressed by putting a descending index on NUM. The second is that
it flat doesn't work multi-user, which may or may not be important to
you. If you absolutely must have sequential numbers, follow Alexandre
Benson Smith's suggestion, but be aware that any mechanism that produces
reliably sequential numbers will serialize updates.
Regards,
Ann