How to show range of available times of the day based on marked intervals of the schedule of appointments in POSTGRES?

Asked

Viewed 45 times

0

I need to show all available time slots for the day that don’t have appointments yet. Thus, you can choose the time still available to dial. I have already been able to detect overlapping commitments using OVERLAP when registering a new commitment. However, I could not show the intervals of the day when I have no appointment and using OVERLAP, I can only compare if the inserted time interval overlaps with others.

My table:

CREATE TABLE compromisso
(
  id serial NOT NULL,
  data_compromisso date,
  descricao_compromisso varchar(100),
  hora_inicio time without time zone,
  hora_fim time without time zone
)

I want to show you the schedule of the day still open.

  • How to mount this table ? What is the rule of the interval ?

  • Define precisely what you call "available times" as well as "start time of appointment", can it be any time or have some rule like, is fixed every half hour or every 1 hour? Or the start and end can be any and the available times are the intervals between the end and start of commitments?

  • u need to set a default duration of a commitment, to tell which others are available

  • If each appointment has fixed duration and predetermined starts (e.g. every 1 hour from 8:00 to 17:00) you can use the function generate_series to generate all possible beginnings and check the vacant schedules, e.g. through a LEFT OUTER JOIN function result with its table compromisso in which compromisso.hora_inicio be it NULL.

  • Good morning, everyone! First of all, I would like to thank you for your readiness and warmth. I believe what I’m about to say will answer everyone, well, come on! " Available times"are all times of the day, that is, 12 hours, from 08:00 A.M to 20:00 P.M. And the DURATION INTERVAL is defined by the user when filling in the data, and the start time is given by "start time" and the end time by "end time".

  • Important detail, as this is the structure of a postgres table, the data will only be saved, that is, a record line will be generated, when a compromise with the requested information is inserted. However, previously, I do not possess the data of the intervals that have no commitment during the day. Soon, I would have to make a DEDUCTION of the possible times on the day less those I already have REGISTERED, which can no longer appear as vacant hours because THERE IS ALREADY a record, appointment, scheduled for this time.

  • You understand the problem, you can create a FUNCTION by checking if in the 12 hours interval, 08:00 A.M to 20:00 P.M, there are vacant schedules, IE, no scheduled appointments yet, and if there is return the vacant hours so that I can show the customer to choose and schedule his appointment?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.