Autor Beitrag
kachel81
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Di 30.05.06 12:22 
Hallo,

ich würde gern die Ergebnismenge eines Selects in zufälliger Reihenfolge sortieren lassen. Scheinbar funktioniert das im Firebird aber nicht wie gewünscht. Folgendes habe ich bereits versucht:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
select
  *
from
  foo
order by
  rand()


Wobei rand() die Standard-UDF, die mit Firebird ausgeliefert wird, ist.

Die Problematik besteht darin, daß rand(), scheinbar aufgrund der hohen Ausführungsgeschwindigkeit des SELECTS immer den selben Wert ausspuckt,
so daß die Ergebnismenge immer nach dem Primary-Key sortiert wird.

Weiß jemand ein Workaround?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 30.05.06 13:24 
Verwende srand()

_________________
Markus Kinzler.
kachel81 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Di 30.05.06 16:36 
Kann es sein das die IB_UDF_srand erst ab Firebird 2.0 mitgeliefert wird.
In der aktuellen Version 1.5.3 scheint die Funktion noch nicht zu existieren.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 30.05.06 16:46 
Jam man hat aus der einen UDF rand() 2 gemacht: rand(), srand(). Die 2. scheint das selbe wir rand bei der alten zu machen ( Random mit setzen des Seeds anhand der Zeit). Die neue rand() setzt den Seed nicht neu.
Einloggen, um Attachments anzusehen!
_________________
Markus Kinzler.
kachel81 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Di 30.05.06 17:08 
Danke, das funktioniert prima!