
create table cash.reservation2 as
    select id, (interval).begints as begints, (interval).endts as endts,
           resnumber, vehicle, member
      from cash.reservation;

insert into cash.reservation2(id, begints, endts, resnumber, vehicle, member)
   with members as (
      select id as mem,
             rank() over(order by membernr) as mrang
        from cash.member
   ), cars as (
      select id as car,
             rank() over(order by licenseplate) as crang
        from cash.vehicle
   ), nums as (
   select i, floor(random() * 10 * i)::int as r
     from generate_series(1000001, 2000000, 1) i
   )
   select i,
          '2021-11-11 00:00:00'::Timestamp + (interval '1hour' * r),
          '2021-11-11 00:00:00'::Timestamp + (interval '1hour' * r) + (interval '3h'),
          i, car, mem
     from nums, cars, members
    where members.mrang = mod(r, (select max(mrang) from members)) + 1
          and cars.crang = mod(r, (select max(crang) from cars)) + 1;

