Skip to content

Instantly share code, notes, and snippets.

@fljdin
Last active Jun 8, 2021
Embed
What would you like to do?
Sample demo for daterange blogpost
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