相关疑难解决方法(0)

如何在Postgres预订中找到第一个免费开始时间

除星期日和公众假期外,工作时间为上午10:00至晚上21:00.

他们的工作每隔15分钟保留一次.工作时间为15分钟至4小时.整个工作必须适合单日.

如何找到Postgres 9.3中从当前日期和时间开始未在指定时间内保留的第一个最近的免费开始时间?

例如,Mary已于12:30至16:00预订,John已于12:00至13:00预订

Reservat表包含预留,yksus2表包含工作,pyha表包含公共假期.表结构如下.如果这有帮助,可以改变储存结构.

查询最长的开始时间为1.5小时,应该返回

John 2014-10-28 10:00
Mary 2014-10-28 10:00
John 2014-10-28 10:15
Mary 2014-10-28 10:15
John 2014-10-28 10:30
Mary 2014-10-28 10:30
Mary 2014-10-28 11:00
John 2014-10-28 13:00
Mary 2014-10-28 16:00
Mary 2014-10-28 16:15
Mary 2014-10-28 16:30
... etc and also starting from next days
Run Code Online (Sandbox Code Playgroud)

我尝试了基于如何从PostgreSql中的预约返回工作时间的答案的查询下面但它返回错误的结果:

MARY  2014-10-28 13:00:00
MARY  2014-10-29 22:34:40.850255
JOHN  2014-10-30 22:34:40.850255
MARY  2014-10-31 22:34:40.850255
MARY  2014-11-03 22:34:40.850255
Run Code Online (Sandbox Code Playgroud)

此外,还不会返回10:00,10:30等滑动开始时间.
如何获得适当的首次预订?

返回错误结果的查询是:

insert into reservat (objekt2, during) values 
('MARY', '[2014-10-28 11:30:00,2014-10-28 …
Run Code Online (Sandbox Code Playgroud)

sql postgresql schedule range

6
推荐指数
1
解决办法
492
查看次数

如何在PostgreSql中的预订表中找到第一个空闲时间

预订表包含预订开始日期,开始时间和持续时间.开始时间是工作时间的8:00到18:00工作时间的半小时增量.持续时间也是一天半小时的增量.

CREATE TABLE reservation (
  startdate date not null,  -- start date
  starthour numeric(4,1) not null , -- start hour 8 8.5 9 9.5  ..  16.5 17 17.5
  duration  Numeric(3,1) not null, -- duration by hours 0.5 1 1.5 .. 9 9.5 10
  primary key (startdate, starthour)
);
Run Code Online (Sandbox Code Playgroud)

如果需要,表结构可以更改.

如何在表中找到第一个免费半小时的未预约?如果表包含,则等式

startdate   starthour  duration 
14          9           1              -- ends at 9:59
14          10          1.5            -- ends at 11:29, e.q there is 30 minute gap before next
14          12          2
14          16 …
Run Code Online (Sandbox Code Playgroud)

sql postgresql schedule postgresql-9.2

3
推荐指数
1
解决办法
1341
查看次数

预订表中仅允许工作时间

PostgreSql 9.2 保留表定义为

CREATE EXTENSION btree_gist;
CREATE TABLE schedule (
  id serial primary key,
  during tsrange not null,
  EXCLUDE USING gist (during WITH &&)
);
Run Code Online (Sandbox Code Playgroud)

假期见表

CREATE TABLE holiday ( day primary key );
Run Code Online (Sandbox Code Playgroud)

工作日工作时间为 8:00 至 18:00,且只能以 30 分钟为间隔进行预订。如何向 while 值添加约束,以便仅允许在工作时间进行预订:

  1. tsrange 中的开始日期和结束日期始终相同。
  2. 开始和结束日期不能是星期六和星期日
  3. 开始和结束日期不能出现在公共假期表中
  4. 开始时间只能为 8:00、8:30、9:00、9:30、... 16:00、16:30、17:00 或 17:30(含)
  5. 结束时间只能为 8:30、9:00、9:30、... 16:00、16:30、17:00、17:30 或 18:00(不含)

将这些或其中一些约束添加到该表中是否合理?如果有,如何添加?如果有帮助的话,可以更改计划表结构。

sql postgresql database-design schedule postgresql-9.2

2
推荐指数
1
解决办法
579
查看次数