Re: How to implement expiration in PostgreSQL?

Поиск
Список
Период
Сортировка
От Vincent Veyron
Тема Re: How to implement expiration in PostgreSQL?
Дата
Msg-id 20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr
обсуждение исходный текст
Ответ на How to implement expiration in PostgreSQL?  (Glen Huang <heyhgl@gmail.com>)
Список pgsql-general
On Thu, 1 Apr 2021 09:51:38 +0800
Glen Huang <heyhgl@gmail.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
maintainmembership 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
'issuenumber' 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
forvery 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



В списке pgsql-general по дате отправления:

Предыдущее
От: Joao Miguel Ferreira
Дата:
Сообщение: Re: pass non-formated query to PL function
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Have I found an interval arithmetic bug?