Skip to content

Custom SQL Validation

The Custom SQL Validation rule executes custom SQL queries to validate specific data quality conditions.
This rule is commonly used to:

  • Implement complex validation logic beyond standard rules
  • Validate business-specific data relationships
  • Check cross-table data integrity

Example Usage:

  • Ensure product prices are positive values across multiple tables
  • Validate that customer orders reference existing customer IDs

Important Requirement:
The custom SQL query must return a result set with a column named is_valid, where:

  • 1 indicates a passing record
  • 0 indicates a failing record

Configuration Fields

Rule-Specific Configuration

Field NameDescriptionRequiredData Type
QuerySQL query returning an is_valid column (1=pass, 0=fail)YesString

Success Criteria Configuration

This section defines how the rule’s outcome is measured against expected thresholds.

Field NameDescriptionRequiredOptions / Format
OperatorComparison operation for result countYesGreaterThan, LessThan, EqualTo, Between
Threshold ValueValue for comparison (single value for most operators)ConditionalNumber
Threshold MinMinimum value (for Between operator)ConditionalNumber
Threshold MaxMaximum value (for Between operator)ConditionalNumber
Is PercentageWhether the threshold represents a percentage of total rowsNotrue / false (default: false)
Allow NullsWhether null values should be treated as validNotrue / false (default: false)
Check For MatchWhen false, validates for negation of the conditionNotrue / false (default: true)

Sample Input Data

Table: product_sales_data

IDProduct NameCategoryPrice
1RefrigeratorAppliances899
2ChairFurniture120
3SmartwatchAppliances250
4LaptopElectronics1200
5SmartphoneElectronics800

Sample Configurations

Example 1: Category Validation

Configuration FieldValue
QuerySELECT CASE WHEN Category IN ('Appliances','Electronics') THEN 1 ELSE 0 END AS is_valid FROM product_sales_data
OperatorBetween
Threshold Min3
Threshold Max5
Is Percentagefalse
Allow Nullsfalse

Explanation:
Validates that 3–5 records belong to either ‘Appliances’ or ‘Electronics’ categories.


Sample Output

Column NameRule NameSuccess CountFailure CountNull CountWithin Threshold
CategoryCustom SQL Validation410Yes