Subject | Re: [ib-support] Setting a generator to the maximum value of the primary key |
---|---|
Author | Lucas Franzen |
Post date | 2001-10-05T14:22:01Z |
Stevio schrieb:
Sometimes I'm extremely over-cautious :-)
Just try sth. like: SELECT 'HELLO WORLD' from MYTABLE (where 'HELLO
WORLD' is not a field name of Mytable, but a constant string).
The result will be n-times 'HELLO WORLD' where n is the number of
records in MYTABLE.
Since RDB$DATABASE has also exactly one record, and SELECT GEN_ID ... is
nothing else then asking for a generator value, you can use this trick
to achieve what you want, this statement will be "executed" exactly one
time.
Regards
Luc.
>You're right.
> Thanks Luc.
>
> The following code, modified from what you gave me, does what I am looking
> for fine:
> SELECT GEN_ID(GEN_NEW_AUTHOR_ID, (SELECT MAX (AUTHOR_ID) FROM AUTHOR)) FROM
> RDB$DATABASE
>
> I don't need to add 1 to it, as I understand, because the first time the
> code is used it will give me the next value, not the current value, for the
> new record being added. If this is wrong please tell me.
Sometimes I'm extremely over-cautious :-)
>You can select "against" any table if you like to.
> Also, I tried this code without the SELECT .... FROM RDB$DATABASE parts code
> and it didn't work. Why do I need this "select from" round the generator
> code?
Just try sth. like: SELECT 'HELLO WORLD' from MYTABLE (where 'HELLO
WORLD' is not a field name of Mytable, but a constant string).
The result will be n-times 'HELLO WORLD' where n is the number of
records in MYTABLE.
Since RDB$DATABASE has also exactly one record, and SELECT GEN_ID ... is
nothing else then asking for a generator value, you can use this trick
to achieve what you want, this statement will be "executed" exactly one
time.
Regards
Luc.