in sql, how to choose random time in from records having from and thru timestamp

Mohamad

New Member
have records, each having\[code\]pk_id serial primary key,key varchar(20),...from_ts timestamp(0) not null,thru_ts timestamp(0) not null,\[/code\]wish to choose random time from intervals as determined by \[code\]from_ts\[/code\] to \[code\]thru_ts\[/code\]a record with a two hour interval should have twice as much chance of being selected as a record with a one hour interval.records having the same key are disjoint - there are no overlapping timeswish to select the \[code\]pk_id\[/code\] and the random timestamp.\[code\]select pk_id, ???from rcdswhere key = 'abc'\[/code\]using \[code\]postgres\[/code\], so ANSI plus \[code\]interval\[/code\] datatype
 
Top