Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Ray O'Donnell
On 03/07/2021 21:13, Adrian Klaver wrote: On 7/3/21 12:16 PM, Ray O'Donnell wrote: Yes, you're right - I realised that after I sent my last email. The inner loop in the function should have matched overlapping bookings by aircraft registration: -- For each booking, check whether there ar

Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Adrian Klaver
On 7/3/21 12:16 PM, Ray O'Donnell wrote: On 03/07/2021 18:59, Adrian Klaver wrote: The booking_id for aircraft B2CA with booking_time of  ["2021-07-03 11:00:00-07","2021-07-03 14:00:00-07"] is not accounted for. There is a step missing that accounts for bookings being assigned to a particul

Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Ray O'Donnell
On 03/07/2021 18:59, Adrian Klaver wrote: I'm not sure this is doing what you think it is; [...]  select * from get_visible_bookings();  booking_id | aircraft_reg | type_code | booking_time | owner_uid | owner_name +--+---+--

Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Adrian Klaver
On 7/3/21 9:32 AM, Ray O'Donnell wrote: On 27/06/2021 23:41, Ray O'Donnell wrote: Hi all, I'm playing with timestamptz ranges for a hobby project. I have a table with a tstzrange column, in which the timestamps can overlap; where they do, rows with a higher priority (derived from a bigint prima

Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Ray O'Donnell
On 27/06/2021 23:41, Ray O'Donnell wrote: Hi all, I'm playing with timestamptz ranges for a hobby project. I have a table with a tstzrange column, in which the timestamps can overlap; where they do, rows with a higher priority (derived from a bigint primary key column) should be picked. What I'

Re: Overlapping timestamptz ranges with priority

2021-07-03 Thread Ray O'Donnell
On 29/06/2021 22:49, Adrian Klaver wrote: If I'm following correctly then: 1) Under old system there where preset two hour slots over a day period, where the period was say 8:00 to 16:00 2) You now want to allow user defined two hour slots over the same period, where a slot can't start befor

Re: Overlapping timestamptz ranges with priority

2021-06-29 Thread Adrian Klaver
On 6/29/21 2:30 PM, Ray O'Donnell wrote: On 29/06/2021 22:10, Adrian Klaver wrote: The queued bookings are for a particular aircraft or a particular time slot? They're for an aircraft. On the old system, they could only be for a slot - so if someone had booked, say, a two-hour slot, then an

Re: Overlapping timestamptz ranges with priority

2021-06-29 Thread Ray O'Donnell
On 29/06/2021 22:10, Adrian Klaver wrote: The queued bookings are for a particular aircraft or a particular time slot? They're for an aircraft. On the old system, they could only be for a slot - so if someone had booked, say, a two-hour slot, then anyone queued behind them could only queue

Re: Overlapping timestamptz ranges with priority

2021-06-29 Thread Adrian Klaver
On 6/29/21 12:49 PM, Ray O'Donnell wrote: On 29/06/2021 20:43, Adrian Klaver wrote: An ounce of prevention is worth a pound of cure: 1) Install btree_gist create extension btree_gist ; 2) create table bookings ( booking_id bigint not null, aircraft_id integer, booking_time_star

Re: Overlapping timestamptz ranges with priority

2021-06-29 Thread Ray O'Donnell
On 29/06/2021 20:43, Adrian Klaver wrote: An ounce of prevention is worth a pound of cure: 1) Install btree_gist create extension btree_gist ; 2) create table bookings (     booking_id bigint not null,     aircraft_id integer,     booking_time_start timestamptz,     booking_time_end timest

Re: Overlapping timestamptz ranges with priority

2021-06-29 Thread Adrian Klaver
On 6/28/21 3:05 AM, Ray O'Donnell wrote: On 28/06/2021 00:52, Adrian Klaver wrote: On 6/27/21 3:41 PM, Ray O'Donnell wrote: Here's a slightly simplified example: create table bookings ( booking_id bigint not null, booking_time tstzrange not null, constraint bookings_pk prima

Re: Overlapping timestamptz ranges with priority

2021-06-28 Thread Ray O'Donnell
On 28/06/2021 00:52, Adrian Klaver wrote: On 6/27/21 3:41 PM, Ray O'Donnell wrote: Here's a slightly simplified example: create table bookings ( booking_id bigint not null, booking_time tstzrange not null, constraint bookings_pk primary key (booking_id) ); It seems to me th

Re: Overlapping timestamptz ranges with priority

2021-06-28 Thread Alban Hertroys
> On 28 Jun 2021, at 0:41, Ray O'Donnell wrote: > > Hi all, > (…) > create table bookings ( >booking_id bigint not null, >booking_time tstzrange not null, > >constraint bookings_pk primary key (booking_id) > ); > > insert into bookings (booking_id, booking_time) values > (1, ts

Re: Overlapping timestamptz ranges with priority

2021-06-27 Thread Adrian Klaver
On 6/27/21 3:41 PM, Ray O'Donnell wrote: Hi all, I'm playing with timestamptz ranges for a hobby project. I have a table with a tstzrange column, in which the timestamps can overlap; where they do, rows with a higher priority (derived from a bigint primary key column) should be picked. What

Overlapping timestamptz ranges with priority

2021-06-27 Thread Ray O'Donnell
Hi all, I'm playing with timestamptz ranges for a hobby project. I have a table with a tstzrange column, in which the timestamps can overlap; where they do, rows with a higher priority (derived from a bigint primary key column) should be picked. What I'd like to do is present a view which sh