Optimizing Pl/PGSQL stored proc (nested conditionals)... - Mailing list pgsql-general

From Sean Chittenden
Subject Optimizing Pl/PGSQL stored proc (nested conditionals)...
Date
Msg-id 20020303100905.G20143@ninja1.internal
Whole thread Raw
List pgsql-general
Howdy.  I've got a quick snippet below of a stored procedure that sets
utc_end_date to the time when the row is disabled.  The reverse is
true also that if it's enabled, then it will remove the utc_end_date
and set it to NULL.  Anyway, I had to use nested IF blocks because I
couldn't get the case or switch statement to work.  Is this the most
optimal way to do this?  -sc

/* Validates and sets the end_date */
CREATE FUNCTION update_enabled() RETURNS opaque AS '
BEGIN
        IF NEW.enabled = ''y'' OR NEW.enabled = ''n'' THEN
                IF NEW.enabled = ''y'' THEN
                        NEW.utc_end_date := NULL;
                ELSE
                        NEW.utc_end_date := (SELECT NOW());
                END IF;
        ELSE
                IF NEW.enabled IS NOT NULL THEN
                        RAISE EXCEPTION ''Invalid enabled value (%): can be only (y) or (n)'', NEW.enabled;
                END IF;
        END IF;
        RETURN NEW;
END;
' LANGUAGE 'plpgsql'


--
Sean Chittenden

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Maximum size of identifiers names ?
Next
From: Patrick Welche
Date:
Subject: Re: oids vs. serial question