Subject | Re: [firebird-support] Generator |
---|---|
Author | Martijn Tonies |
Post date | 2012-05-08T13:16:23Z |
Hello Olaf,
there will be gaps. Either the transaction fails for a logical reason
or it fails for another reason (eg: network connection down just
after the INSERT but before the COMMIT).
So, you can have the last ID of 100, but no IDs until you reach 92
and then you have a couple and then you have another gap.
with the FIRST command?
SELECT FIRST 10 SKIP 5 *
FROM yourtable
ORDER BY idcolumn DESC
With regards,
Martijn Tonies
Upscene Productions
http://www.upscene.com
Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!
> my description was not good.Whenever you use a generator to generate IDs, it can happen that
>
> I need the value in a stored procedure, not by inserting the data! By
> inserting I have a trigger. new.id = gen_id(generator,1);
>
> I have a table with some records. Now I need the last 10 inserted records
> with an offset of 5 for example. The last ID is 100, I want to get the
> records (IDs) 95 to 86 in this case. If the offset is 10, I need the
> records
> 90 to 81 and so on.
there will be gaps. Either the transaction fails for a logical reason
or it fails for another reason (eg: network connection down just
after the INSERT but before the COMMIT).
So, you can have the last ID of 100, but no IDs until you reach 92
and then you have a couple and then you have another gap.
> To get the last ID I thought it is the best way to use the generator withIf you need the highest few, have you looked at using ORDER BY
> the value 0, but the description warns about errors.
with the FIRST command?
SELECT FIRST 10 SKIP 5 *
FROM yourtable
ORDER BY idcolumn DESC
With regards,
Martijn Tonies
Upscene Productions
http://www.upscene.com
Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!