Last active
June 8, 2021 10:54
-
-
Save fljdin/293984e0f3e55817257cf65d1bb85e5b to your computer and use it in GitHub Desktop.
Sample demo for daterange blogpost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS staff; | |
CREATE TABLE staff ( | |
id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | |
name varchar(50), | |
start date NOT NULL, | |
finish date, | |
period daterange GENERATED ALWAYS AS (daterange(start, finish, '[]')) STORED, | |
CHECK (start < finish OR finish IS NULL) | |
); | |
INSERT INTO staff (name, start, finish) VALUES | |
('Élodie', '2020-05-01', null), | |
('Louise', '2021-01-04', '2021-02-25'), | |
('Stéphane', '2021-01-04', '2021-07-01'), | |
('Hervé', '2021-02-01', '2021-03-01)'), | |
('Martine', '2021-02-01', null), | |
('Philippe', '2021-02-20', '2021-07-02)'), | |
('Jean', '2021-06-01', null), | |
('Édouard', '2021-03-12', '2021-06-01)'), | |
('Lucas', '2021-07-01', '2021-08-31)'), | |
('Mickaël', '2021-07-01', null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment