Received: from localhost (pluto.hub.org [200.46.204.4]) by postgresql.org (Postfix) with ESMTP id DD3799FB2E2 for ; Thu, 2 Nov 2006 14:33:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.4]) (amavisd-new, port 10024) with ESMTP id 09828-03 for ; Thu, 2 Nov 2006 14:33:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tomts13-srv.bellnexxia.net (tomts13.bellnexxia.net [209.226.175.34]) by postgresql.org (Postfix) with ESMTP id 3F0559FB2D8 for ; Thu, 2 Nov 2006 14:33:04 -0400 (AST) Received: from [192.168.1.7] ([65.94.11.249]) by tomts13-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20061102183303.WQQU29052.tomts13-srv.bellnexxia.net@[192.168.1.7]> for ; Thu, 2 Nov 2006 13:33:03 -0500 Message-ID: <454A394C.7020102@zijn-digital.com> Date: Thu, 02 Nov 2006 13:30:36 -0500 From: brian User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: Is there anyway to... References: <20061102171624.GE21312@localhost> <454A357E.6010409@linuxlouis.net> In-Reply-To: <454A357E.6010409@linuxlouis.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/108 X-Sequence-Number: 103204 louis gonzales wrote: > Hello all, > Is there an existing mechanism is postgresql that can automatically > increment/decrement on a daily basis w/out user interaction? The use > case I'm considering is where a student is in some type of contract with > an instructor of some sort, and that contract puts a time limit on the > student requiring her to pay a fee by a certain day. IF that day comes > to pass - or a certain number of days elapse - and that payment > requirement hasn't been met, I want to trigger a function. > > The one requirement I want to impose is, that no end user of the DB > application, needs to do anything to set the trigger, other than the > initialization of making the student of this type. > > An example would be: > Day1 - Application user(typically the instructor) creates a profile for > a new student - John Doe, which sets a 30 day time limit for John Doe to > pay $100.00 > Day2 -> Day31 - John Doe didn't make the payment > Day 31 - Trigger of event occurs when the instructor logs in. > > Basically on Day 1 when John Doe's profile was created, I want a > decrement counter to occur daily on his profile(some attribute/timer) > and nothing should happen until day 31 when he doesn't pay. > Further to Andreas' suggestion to use CRON, you don't require a decrement of anything. When the profile is created, your date_created (or whatever) column will be set. Then your script (called by CRON) only needs to test for rows that a) have not paid, and b) are outside the bounds set in the script (eg. MAX_GRACE_PERIOD = 30). brian