Summary
The [upsert].[meta]
procedure is a lightweight controller for inserting or updating metadata attributes related to a specific object. It constructs a compact JSON payload and delegates the logic to [cdm].[patch_upsert]
.
It is ideal for managing metadata flags, status indicators, or classifications for objects like projects, employees, customers, and more.
π§ Key Steps
- Set Defaults
- Automatically fills in values for
authoredby
,sourceid
, andcreate_date
.
- Automatically fills in values for
- Build JSON Payload
- Constructs a small and structured payload using:
object_seq
meta_type
attribute
value
meta_data
(as JSON string)
- Constructs a small and structured payload using:
- Delegate to Patch Upsert
- Passes everything to
[cdm].[patch_upsert]
for smart versioning and insert/update logic.
- Passes everything to
- Debug Output (Optional)
- If
@debug = 1
, prints the payload and procedure reference for traceability.
- If
- Error Handling
- Raises a well-formed error message if anything fails during the operation.
π§ͺ Example Usage
EXEC [upsert].[meta]
@tableName = 'cdm.employee_values',
@object_seq = 'employee_1234',
@meta_type = 'values',
@attribute = 'language',
@value = 'EN',
@meta_data = '{"preferred": true}',
@authoredby = 'jkellett',
@debug = 1;
π¦ Parameters
Parameter | Description |
---|---|
@tableName | The metadata table where the record should be inserted/updated |
@object_seq | The unique identifier for the object (e.g. employee_1234 ) |
@meta_type | The category or theme of the metadata (e.g. values , codes , dates ) |
@attribute | The name of the metadata field (e.g. language , status , region ) |
@value | The value of the attribute (stored as string) |
@meta_data | Optional metadata in JSON format (additional qualifiers or notes) |
@tableType | Template category (meta by default) |
@authoredby | Source name recorded in the insert/update |
@sourceid | Optional source system reference |
@create_date | Optional creation timestamp |
@debug | Enable debug logging of payload and steps |
π§© JSON Payload Example
{
"object_seq": "employee_1234",
"meta_type": "values",
"attribute": "language",
"value": "EN",
"meta_data": "{\"preferred\": true}"
}
β Best Practice
- Use for single-attribute updates where
object_seq
,meta_type
, andattribute
form the natural key. - Ideal for small jobs like tagging objects with flags, lookup mappings, or enrichment values.
- Fits neatly into automation pipelines or UI triggers.