Subject Re: [ib-support] more questions on use of generators
Author Helen Borrie
At 02:06 PM 12-11-02 +0800, you wrote:

>Sorry, to clarify I meant a SELECT in the form of
>SELECT <function> as in SELECT LAST_INSERT_ID() which
>makes intuitive sense to me as opposed to Firebird's:
>
>select gen_id(GENNAME, 0) as GenVal from RDB$Database
>
>which I can't figure out how it works because
>gen_id(GENNAME,n) does not return a value by itself,
>nor does there seem to be any entries in RDB$Database
>if one does a 'select * from RDB$Database'.

It's because, order to SELECT something, you have to select FROM a table,
even if the thing you are selecting isn't a column in the table. That's
SQL for you - it won't let you select from Scotch Mist.

Inside a SP or a trigger you can pull a gen_id() result into a
variable; but of course in dynamic SQL, you don't have variables.

RDB$Database just happens to be "any old table that has one and only one
row". You could create your own table to use instead, if you preferred, as
long as you had some way (e.g. a trigger) to ensure that it would always
have one and only one row.

We all use RDB$Database because it's there. If it's InterBase you're
using, not Firebird, be alerted that Borl have indicated that they might at
some point prevent user queries on RDB$Database.

Helen