pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: Bradley Kieser <brad@sms-speedway.com>
Cc: PgSQL ADMIN <pgsql-admin@postgresql.org>
Subject: Re: OT: using column in an interval
Date: Fri, 24 Mar 2006 18:41:58 -0500
Message-ID: <12667.1143243718@sss.pgh.pa.us> (raw)
In-Reply-To: <20060324140436.N95370@megazone.bigpanda.com>
References: <4422A13D.8060804@sms-speedway.com>
	<20060324140436.N95370@megazone.bigpanda.com>

Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> On Thu, 23 Mar 2006, Bradley Kieser wrote:
>> last_backup: timestamp
>> backup_unit: integer - Represents day, week, quarter, annual, etc. The
>> text is stored in backup_code (e.g. 'days', 'months')
>> backup_period: integer - Represents the skip factor.

> CAST( backup_period || ' ' || backup_code AS interval) should give you an
> interval. If the units were constant, I'd say that using integer *
> interval is a better idea, but I think you'd need a function that say took
> backup_unit and gave back an interval of 1 <unit> to make that work, but
> that would possibly be cleaner overall.

This really seems like a case of a poorly chosen representation.  Why
not just have the backup interval as an interval column, ie

last_backup: timestamptz (not timestamp, btw)
backup_interval: interval, can be eg '3 days' or '1 month' or whatever.

Then you can do

WHERE last_backup + backup_interval <= current_timestamp

			regards, tom lane



view thread (3+ messages)

Message-ID: <12667.1143243718@sss.pgh.pa.us>
Permalink:  ../12667.1143243718@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12667.1143243718@sss.pgh.pa.us

 · 

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sszabo@megazone.bigpanda.com, brad@sms-speedway.com
  Subject: Re: OT: using column in an interval
  In-Reply-To: <12667.1143243718@sss.pgh.pa.us>
  References: <4422A13D.8060804@sms-speedway.com> <20060324140436.N95370@megazone.bigpanda.com> <12667.1143243718@sss.pgh.pa.us>

* 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