Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

psql - How to exclude overlapping timerange but accept common bound?

I want to prevent insertion of overlapping timerange but accept a common bound. Given the below timerange (type TSRANGE) :

[01-01-2021 10:00:00, 01-01-2021 11:00:00]

I want this timerange to be accepted :

[01-01-2021 11:00:00, 01-01-2021 12:00:00]

But this one to be excluded :

[01-01-2021 09:00:00, 01-01-2021 10:30:00]

Is there a simple way to do this with gist ? For now I use the restriction from the doc :

EXCLUDE USING gist ... WITH &&

But the one I want to insert is excluded.

ANSWER

Answering my own question. The gist is actually fine. When inserting a new time range I was using :

INSERT INTO ... tsrange('2021-01-01 10:00', '2021-01-01 11:00', '[]')

Use '()' instead of '[]' if you want to set different exclusion.

question from:https://stackoverflow.com/questions/65919693/how-to-exclude-overlapping-timerange-but-accept-common-bound

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...