From: | Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: How to implement expiration in PostgreSQL? |
Date: | 2021-04-02 15:00:29 |
Message-ID: | 20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 1 Apr 2021 09:51:38 +0800
Glen Huang <heyhgl(at)gmail(dot)com> wrote:
Hi,
If you are in a position to modify your design, I believe your problem comes from this part :
> WHERE paid OR join_time > now() - ‘1h’::interval
which suggests that there is a 'paid' column being updated. I learned that the proper way to structure a database to maintain membership and save a lot of grief is the following :
create table seated_member(
name text not null,
...,
join_time date not null default now,
validity integer not null default 1
);
where validity is a number of whatever unit is appropriate; typically 'year' for a club membership (newspapers use 'issue number' instead of join_time to account for strikes, when no paper is issued). In your case, 'hour' I suppose.
All you need to do when the member pays is to update the 'validity' field with the proper amount of units. This makes for very simple and efficient queries to retrieve the data, and you only need to write :
WHERE now() < join_time + 'validity hours'::interval
to retrieve valid accounts.
Accounts expire automatically, deleting them can wait; it also makes it easier to send reminders before the expiration date
--
Bien à vous, Vincent Veyron
https://marica.fr
Logiciel de gestion des contentieux juridiques, des contrats et des sinistres d'assurance
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2021-04-02 18:05:49 | Re: Have I found an interval arithmetic bug? |
Previous Message | Joao Miguel Ferreira | 2021-04-02 13:45:24 | Re: pass non-formated query to PL function |