【发布时间】:2020-09-01 21:38:32
【问题描述】:
您好,希望有人能帮助我。
假设我的桌子上有以下内容
名称文本 无时区的 startTime 时间戳 没有时区的 endTime 时间戳
这是我想要做的:
我正在尝试检查即将添加到数据库中的时间是否会与表上已有的时间重叠。
样本:
name startTime endTime
---------|------------------------|----------------------
tommy | 2019-07-10 08:30:00 | 2019-07-10 10:30:00
tommy | 2019-07-10 10:31:00 | 2019-07-10 11:30:00
tommy | 2019-07-10 07:30:00 | 2019-07-10 09:00:00 <=== if I click enter to enter this tird schedulle for this user, the sistem will give me a conflict message because this user already has a schedulle that start from 2019-07-10 08:30:00 to 2019-07-10 10:30:00 on our first row of the table.
至于我要在数据库中插入的代码,我只有这个简单的 php
$sql = "insert into horarios (name, startTime, endTime) values ('$name', '$startTime', '$endTime');";
$res = @pg_query ($con, $sql);
if ($res == NULL){
echo "Query failed.";
exit (0);
}
【问题讨论】:
标签: php postgresql datetime sql-insert check-constraints