OT: using column in an interval

From: Bradley Kieser <brad(at)sms-speedway(dot)com>
To: PgSQL ADMIN <pgsql-admin(at)postgresql(dot)org>
Subject: OT: using column in an interval
Date: 2006-03-23 13:23:09
Message-ID: 4422A13D.8060804@sms-speedway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

All,

I know that this isn't strictly an admin question but please forgive me
for asking.
I am writing a (admin) job which does a select off a PG database based
on three columns:

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.

i.e. if backup_unit is 1 (days) and period is 3, then together they
represent "every three days".

Obviously I want to do something like:

select id, client
from backupSchedule
where last_backup + interval backup_period backup_code <= CURRENT_DATE

However, interval seems to only take text such as
inverval '3 days'

and I get an error even with this:

select id, client
from backupSchedule
where last_backup + interval backup_period::text || backup_code <=
CURRENT_DATE

Can someone please point me to the right statement to use for
column-based interval arithmetic?
The docs all give hardcoded text strings in examples. Not found one yet
with a proper column-based query!

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Koen Martens 2006-03-23 15:02:04 Random disconnects
Previous Message Peter Eisentraut 2006-03-22 22:48:03 Re: pgadmin 1.4 + pgsql 8.1.0