All pastes #617464 Raw Edit

stored procedure

public text v1 · immutable
·published 2007-07-13 08:23 UTC
rendered paste body
CREATE OR REPLACE FUNCTION "spInsertQuota"(varchar)
        RETURNS INTEGER AS '
        DECLARE
                intID INTEGER;
                        
                vchDescription ALIAS FOR $1;
                                        
        BEGIN
                        
                SELECT INTO intID "QuotaID" FROM "Quota" WHERE "QuotaDescription" = vchDescription;

                IF intID IS NULL THEN
                        SELECT INTO intID nextval(''"Quota_QuotaID_seq"'');
                                
                        INSERT INTO "Quota"("QuotaID", "QuotaDescription")
                        VALUES(intID, vchDescription);
                END IF;
                        
                RETURN intID;
                                
                END;
' LANGUAGE 'plpgsql' STABLE;