diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py index 1d458229484..114167da83f 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py @@ -453,13 +453,24 @@ def _pg_tier_validator(tier, sku_info): def compare_sku_names(sku_1, sku_2): - regex_pattern = r"_v(\d)" + regex_pattern = r"\D+(?P\d+)\D+(?P\d*)" sku_1_match = re.search(regex_pattern, sku_1) sku_2_match = re.search(regex_pattern, sku_2) - return (int(sku_2_match.group(1)) if sku_2_match else 0) - \ - (int(sku_1_match.group(1)) if sku_1_match else 0) + # the case where version number is different, sort by the version number first + if sku_1_match.group('version') and int(sku_2_match.group('version')) > int(sku_1_match.group('version')): + return 1 + if sku_1_match.group('version') and int(sku_2_match.group('version')) < int(sku_1_match.group('version')): + return -1 + + # the case where version number is the same, we want to sort by the core number + if int(sku_2_match.group('core_number')) > int(sku_1_match.group('core_number')): + return 1 + if int(sku_2_match.group('core_number')) < int(sku_1_match.group('core_number')): + return -1 + + return 0 def _pg_sku_name_validator(sku_name, sku_info, tier, instance):