Skip site navigation (1) Skip section navigation (2)

PL/pgSQL

From: Michael Fork <mfork(at)toledolink(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: PL/pgSQL
Date: 2000-04-05 23:58:11
Message-ID: Pine.BSI.4.21.0004051953250.13461-100000@glass.toledolink.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
After creating the following trigger and function, no more records
are added to the datbase, with no visible errors, exceptions, etc.  Does
anyone see my mistake?  Thanks in advance.

CREATE FUNCTION ti_acct_update() RETURNS OPAQUE AS
            '
	DECLARE
          time int4;
        BEGIN
          IF NEW.acctstatustype = ''STOP'' THEN
            SELECT ti_time INTO prev_time FROM tiacct WHERE
              ((NEW.username = ti_username) AND 
              (datepart(''month'', NEW.tstamp) == ti_month) AND 
              (datepart(''year'',NEW.tstamp) == ti_year));
            IF NOT FOUND THEN
              INSERT INTO tiacct (ti_username, ti_month, ti_year, ti_time)
                  VALUES (NEW.username, datepart(''month'', NEW.tstamp), 
                  datepart(''year'',NEW.tstamp), NEW.acctsessiontime);
             ELSE
               time := prev_time + NEW.acctsessiontime;
               UPDATE tiacct (ti_time) VALUES (time) WHERE 
	         ((NEW.username = ti_username) AND 
                 (datepart(''month'', NEW.tstamp) == ti_month) AND
                 (datepart(''year'',NEW.tstamp) == ti_year));
            END IF;
          END IF;
          RETURN NEW;
        END;
        '
        LANGUAGE 'plpgsql';
            
CREATE TRIGGER ti_acct_update AFTER INSERT ON radacct
FOR EACH ROW EXECUTE PROCEDURE ti_acct_update();

Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio


pgsql-interfaces by date

Next:From: Joseph ShraibmanDate: 2000-04-06 01:12:05
Subject: Re: Debian + PG + JDBC
Previous:From: Nikolai TurchanikovDate: 2000-04-05 23:34:26
Subject: JDBC: Method setBinaryStream Question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group