SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create function GetMaxVersionCustom(Version1 character varying, Version2 character varying) RETURNS character varying AS $$ DECLARE -- tmp_max_version text := '0.0.0'; tmp_max_version text := Version1; splited_version1 text[]; splited_version2 text[]; iterator int := 0; cmd text; BEGIN IF (Version1 ISNULL AND Version2 IS NOT NULL) THEN tmp_max_version := Version2; ELSE IF (Version1 IS NOT NULL AND Version2 ISNULL) THEN tmp_max_version := Version1; END IF; END IF; IF (Version1 IS NOT NULL AND Version2 IS NOT NULL) THEN -- splited_version1 := regexp_split_to_array(CAST(Version1 as text), '.'); -- splited_version2 := regexp_split_to_array(CAST(Version2 as text), '.'); -- splited_version1 := regexp_match(CAST(Version1 as text), '(\d+)\.(\d+)\.(\d+)'); -- splited_version2 := regexp_match(CAST(Version2 as text), '(\d+)\.(\d+)\.(\d+)'); splited_version1 := regexp_match(Version1, '(\d+)\.(\d+)\.(\d+)'); splited_version2 := regexp_match(Version2, '(\d+)\.(\d+)\.(\d+)'); FOR iterator IN 0..2 LOOP IF (CAST(splited_version1[iterator] AS int) > CAST(splited_version2[iterator] AS int)) THEN tmp_max_version := CAST(Version1 as text); EXIT; ELSE IF (CAST(splited_version1[iterator] AS int) < CAST(splited_version2[iterator] AS int)) THEN tmp_max_version := CAST(Version2 as text); EXIT; -- ELSE -- IF (CAST(splited_version1[iterator] AS int) = CAST(splited_version2[iterator] AS int)) -- THEN -- tmp_max_version := CAST(Version1 as text); -- END IF; END IF; END IF; END LOOP; END IF; RETURN CAST(tmp_max_version as character varying); END $$ LANGUAGE plpgsql
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear