71 lines
2.3 KiB
Markdown
71 lines
2.3 KiB
Markdown
# Function: grok_validate_matv_inputs
|
|
|
|
## Overview
|
|
This function validates the existence of a materialized view and its source view before performing operations on them, ensuring inputs are valid.
|
|
|
|
## Schema
|
|
`config.grok_validate_matv_inputs`
|
|
|
|
## Parameters
|
|
- `schema_name` (text): Schema containing the materialized view and source view
|
|
- `matview_name` (text): Name of the materialized view
|
|
- `vtw_name` (text): Optional name of the source view (if not provided, derived from matview_name)
|
|
|
|
## Return Value
|
|
Returns a JSONB object with validation results:
|
|
|
|
Success case:
|
|
```json
|
|
{
|
|
"full_matview_name": "schema.matview_name",
|
|
"full_vtw_name": "schema.vtw_name",
|
|
"notes": []
|
|
}
|
|
```
|
|
|
|
Error case:
|
|
```json
|
|
{
|
|
"error": "Materialized view schema.matview_name does not exist",
|
|
"notes": []
|
|
}
|
|
```
|
|
|
|
## Description
|
|
This function performs input validation before executing operations on materialized views by:
|
|
|
|
1. Constructing the fully qualified names for the materialized view and source view
|
|
2. Checking if the materialized view exists in pg_matviews
|
|
3. Checking if the source view exists in either pg_views or pg_tables
|
|
4. Returning appropriate error messages if either object is missing
|
|
|
|
If `vtw_name` is not provided, the function derives it by replacing 'matc_' with 'vtw_' in the materialized view name, following the standard naming convention.
|
|
|
|
## Validation Checks
|
|
The function checks:
|
|
- Materialized view existence using the pg_matviews system catalog
|
|
- Source view existence using both pg_views and pg_tables system catalogs (handles both views and tables)
|
|
|
|
## Error Handling
|
|
If validation fails, the function returns a descriptive error message indicating which object is missing. If an unexpected error occurs during validation, it returns a generic error message with the exception details.
|
|
|
|
## Dependencies
|
|
This function doesn't call other functions but is likely called by materialized view management functions before performing operations.
|
|
|
|
## Usage Example
|
|
```sql
|
|
-- Validate materialized view with automatic source view name derivation
|
|
SELECT config.grok_validate_matv_inputs(
|
|
'analytics',
|
|
'matc_daily_sales',
|
|
NULL
|
|
);
|
|
|
|
-- Validate materialized view with explicit source view name
|
|
SELECT config.grok_validate_matv_inputs(
|
|
'analytics',
|
|
'matc_daily_sales',
|
|
'custom_source_view'
|
|
);
|
|
```
|