Subject | AW: AW: [firebird-support] Generator |
---|---|
Author | Olaf Kluge |
Post date | 2012-05-08T13:33:50Z |
Hello
On Tue, 8 May 2012 15:09:34 +0200, "Olaf Kluge" <olaf.kluge@... <mailto:olaf.kluge%40satron.de> >
wrote:
*you* inserted. However. If you want to retrieve the last 10 records it is
still a bad idea to use the generator, because if records were inserted
after your transaction started, then you will see less than 10 records.
It would probably be better to do
SELECT <fields you want> FROM <table> ORDER BY ID DESC ROWS 10
As that will guarantee you get the last 10 records inserted that are
visible to your transaction.
Thank you, but how can I implement the offset in this case? I need the 10 last records, but every workstation has an offset. WS1 vor example needs the 10 last records + an offset of 10. In this case I need the last 20 records and use the Records 11 to 19. The first 10 records I do not need. On one position there is a reading point. Now the skid with a car goes one and one. On the tenth position there is a workstation. This needs the last records, but with an offset of 10. Other workstations needs other offsets.
Thanks a lot.
[Non-text portions of this message have been removed]
On Tue, 8 May 2012 15:09:34 +0200, "Olaf Kluge" <olaf.kluge@... <mailto:olaf.kluge%40satron.de> >
wrote:
> my description was not good.records
>
> 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
> with an offset of 5 for example. The last ID is 100, I want to get thewith
> records (IDs) 95 to 86 in this case. If the offset is 10, I need the
> records
> 90 to 81 and so on.
>
> To get the last ID I thought it is the best way to use the generator
> the value 0, but the description warns about errors.That warning is about assuming that the number represents the last record
*you* inserted. However. If you want to retrieve the last 10 records it is
still a bad idea to use the generator, because if records were inserted
after your transaction started, then you will see less than 10 records.
It would probably be better to do
SELECT <fields you want> FROM <table> ORDER BY ID DESC ROWS 10
As that will guarantee you get the last 10 records inserted that are
visible to your transaction.
Thank you, but how can I implement the offset in this case? I need the 10 last records, but every workstation has an offset. WS1 vor example needs the 10 last records + an offset of 10. In this case I need the last 20 records and use the Records 11 to 19. The first 10 records I do not need. On one position there is a reading point. Now the skid with a car goes one and one. On the tenth position there is a workstation. This needs the last records, but with an offset of 10. Other workstations needs other offsets.
Thanks a lot.
[Non-text portions of this message have been removed]