All pastes #182138 Raw Edit

Anonymous

public text v1 · immutable
#182138 ·published 2006-09-25 19:41 UTC
rendered paste body
psbl=# \df+ merge_blocklist
                                                         List of functions
 Schema |      Name       | Result data type |        Argument data types        |  Owner   | Language | Source code | Description 
--------+-----------------+------------------+-----------------------------------+----------+----------+-------------+-------------
 public | merge_blocklist | void             | inet, timestamp without time zone | postgres | plpgsql  | 
BEGIN
    LOOP 
        UPDATE blocklist SET expires = expiry_time WHERE ip = ipaddr;
        IF found THEN
            RETURN;
        END IF;

        BEGIN
            INSERT INTO blocklist(ip,expires) VALUES (ipaddr, expiry_time);
            RETURN;
        EXCEPTION WHEN unique_violation THEN
            -- do nothing
        END;
    END LOOP;
END;
            | 
(1 row)