Re: OT: using column in an interval - Mailing list pgsql-admin

From Tom Lane
Subject Re: OT: using column in an interval
Date
Msg-id 12667.1143243718@sss.pgh.pa.us
Whole thread Raw
In response to Re: OT: using column in an interval  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-admin
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

pgsql-admin by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Continuous On-line Backups
Next
From: "Sriram Dandapani"
Date:
Subject: WAL file naming convention