CREATE FUNCTION lock_conflict(TEXT, TEXT) RETURNS BOOLEAN LANGUAGE plpgsql AS ' BEGIN IF $1 = ''AccessShareLock'' THEN IF $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''RowShareLock'' THEN IF $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''RowExclusiveLock'' THEN IF $2 = ''ShareLock'' OR $2 = ''ShareRowExclusiveLock'' OR $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''ShareUpdateExclusiveLock'' THEN IF $2 = ''ShareUpdateExclusiveLock'' OR $2 = ''ShareLock'' OR $2 = ''ShareRowExclusiveLock'' OR $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''ShareLock'' THEN IF $2 = ''RowExclusiveLock'' OR $2 = ''ShareUpdateExclusiveLock'' OR $2 = ''ShareRowExclusiveLock'' OR $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''ShareRowExclusiveLock'' THEN IF $2 = ''RowExclusiveLock'' OR $2 = ''ShareUpdateExclusiveLock'' OR $2 = ''ShareLock'' OR $2 = ''ShareRowExclusiveLock'' OR $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''ExclusiveLock'' THEN IF $2 = ''RowShareLock'' OR $2 = ''RowExclusiveLock'' OR $2 = ''ShareUpdateExclusiveLock'' OR $2 = ''ShareLock'' OR $2 = ''ShareRowExclusiveLock'' OR $2 = ''ExclusiveLock'' OR $2 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RETURN FALSE; END IF; ELSIF $1 = ''AccessExclusiveLock'' THEN RETURN TRUE; ELSE RAISE EXCEPTION ''Invalid Lock Mode: %'', $1; END IF; END;'
GO;