Procedure Signature
Purpose and Functionality
Thesilver.load_silver() procedure transforms and cleanses raw data from the bronze layer into curated, business-ready data in the silver layer. This is the second stage of the data warehouse ETL pipeline, where data quality improvements and standardization are applied.
Key responsibilities:
- Data cleansing and standardization
- Removing duplicates and handling nulls
- Transforming coded values into human-readable formats
- Applying business rules and validations
- Type conversions and data formatting
Key Transformations Applied
CRM Customer Information (silver.crm_cust_info)
CRM Product Information (silver.crm_prd_info)
CRM Sales Details (silver.crm_sales_details)
ERP Customer Data (silver.erp_cust_az12)
ERP Location Data (silver.erp_loc_a101)
ERP Product Category Data (silver.erp_px_cat_g1v2)
Steps Performed
Transform CRM Customer Information
Load
silver.crm_cust_info with deduplication, text trimming, and code expansion for marital status and genderTransform CRM Product Information
Load
silver.crm_prd_info with category extraction, null handling, product line expansion, and end date calculationTransform CRM Sales Details
Load
silver.crm_sales_details with date validation, sales amount correction, and price validationClean ERP Customer Data
Load
silver.erp_cust_az12 with ID prefix removal, birthdate validation, and gender standardizationUsage Example
Prerequisites
Error Handling
The procedure implements robust error handling at each transformation step:
- Step-level Exception Handling: Each table transformation is isolated with its own error handler
- Descriptive Error Messages: Errors include the step name and PostgreSQL error details
- Fail-Fast Behavior: Execution halts immediately upon encountering an error
- Performance Metrics: Each step logs execution time for monitoring
- Success Tracking: Counter variables track successful (
v_ok) and failed (v_err) operations
Data Quality Rules
The procedure enforces several data quality rules:| Rule Type | Description | Example |
|---|---|---|
| Deduplication | Keep only latest records | CRM customer info by create date |
| Null Handling | Replace nulls with defaults | Product cost defaults to 0 |
| Date Validation | Reject invalid dates | Future birthdates become NULL |
| Value Standardization | Expand codes to full names | ’M’ → ‘Male’, ‘S’ → ‘Single’ |
| ID Formatting | Remove unwanted characters | Remove ‘NAS’ prefix, dashes |
| Calculated Fields | Derive values from other columns | Sales = Quantity × Price |
| Type Conversion | Convert string dates to DATE type | ’20240101’ → 2024-01-01 |