Php 使用星期日和tsrange防止插入重叠的日期范围
我希望我能解释清楚 我的表具有以下结构Php 使用星期日和tsrange防止插入重叠的日期范围,php,postgresql,Php,Postgresql,我希望我能解释清楚 我的表具有以下结构 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description -----------+---------+-----------+----------+---------+----------+--------------+------------- name | text | |
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
-----------+---------+-----------+----------+---------+----------+--------------+-------------
name | text | | | | extended | |
days_week | text | | | | extended | |
datetime | tsrange | | | | extended | |
Indexes:
"test_name_datetime_excl" EXCLUDE USING gist (name WITH =, datetime WITH &&)
我一直在尝试为同一名称插入相同的日期和时间,但只是更改了每周的天数。我知道我的桌子结构上少了一些东西,但我不知道是什么。
这是我试图实现的示例:
Insert into test values (‘first name’,’ Monday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’);
INSERT 0 1
Insert into test values (‘first name’,’ Monday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’); this will be a error or conflicts with existing key
Insert into test values (‘first name’,’ Monday’, ‘[2020-01-01 10:00, 2020-01-01 10:30)’);
INSERT 0 1
Insert into test values (‘first name’,’ Tuesday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’);
INSERT 0 1
Insert into test values (‘second name’,’ Monday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’);
INSERT 0 1
Insert into test values (‘second name’,’ Monday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’); this will be a error or conflicts with existing key
Insert into test values (‘second name’,’ tuesday’, ‘[2020-01-01 08:30, 2020-01-01 10:00)’);
INSERT 0 1
我希望我解释得很好。
提前感谢我想您只需要在排除索引中添加
天(周
):
create table test (
name text,
days_week text,
datetime tsrange,
exclude using gist (name with =, days_week with =, datetime with &&)
)
这禁止在相同的名称
和天/周
上重叠范围,同时允许其他情况
您的问题格式不正确,请尝试添加您所面临的错误消息,对您所面临的问题进行更具体、更细致的描述。