pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vincent Veyron <vv.lists@wanadoo.fr>
To: pgsql-general@lists.postgresql.org
Subject: Re: How to implement expiration in PostgreSQL?
Date: Fri, 2 Apr 2021 17:00:29 +0200
Message-ID: <20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr> (raw)
In-Reply-To: <3AE654F0-815D-461B-B7D8-A137FC1C6493@gmail.com>
References: <3AE654F0-815D-461B-B7D8-A137FC1C6493@gmail.com>

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 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





view thread (11+ messages)

Message-ID: <20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr>
Permalink:  ../20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr/
Also on:    postgresql.org/message-id/20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: vv.lists@wanadoo.fr
  Subject: Re: How to implement expiration in PostgreSQL?
  In-Reply-To: <20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr>
  References: <3AE654F0-815D-461B-B7D8-A137FC1C6493@gmail.com> <20210402170029.798700ddc425019ed1d01ebf@wanadoo.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox