Stored Procedures and Functions

Stored Procedures and Functions

Guides an AI agent to write stored procedures, functions and triggers for PostgreSQL and MySQL, with error handling, validation and audit patterns.

Skill files9 files

references/

scripts/

templates/

SKILL.md86 lines
1
---
2
name: stored-procedures
3
description: >
4
Implement stored procedures and functions for database logic. Use when
5
creating reusable database routines, complex queries, or server-side
6
calculations.
7
---
8
9
# Stored Procedures & Functions
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement stored procedures, functions, and triggers for business logic, data validation, and performance optimization. Covers procedure design, error handling, and performance considerations.
22
23
## When to Use
24
25
- Business logic encapsulation
26
- Complex multi-step operations
27
- Data validation and constraints
28
- Audit trail maintenance
29
- Performance optimization
30
- Code reusability across applications
31
- Trigger-based automation
32
33
## Quick Start
34
35
**PostgreSQL - Scalar Function:**
36
37
```sql
38
-- Create function returning single value
39
CREATE OR REPLACE FUNCTION calculate_order_total(
40
p_subtotal DECIMAL,
41
p_tax_rate DECIMAL,
42
p_shipping DECIMAL
43
)
44
RETURNS DECIMAL AS $$
45
BEGIN
46
RETURN ROUND((p_subtotal * (1 + p_tax_rate) + p_shipping)::NUMERIC, 2);
47
END;
48
$$ LANGUAGE plpgsql IMMUTABLE;
49
50
-- Use in queries
51
SELECT id, subtotal, calculate_order_total(subtotal, 0.08, 10) as total
52
FROM orders;
53
54
-- Or in application code
55
SELECT * FROM orders
56
WHERE calculate_order_total(subtotal, 0.08, 10) > 100;
57
```
58
59
## Reference Guides
60
61
Detailed implementations in the `references/` directory:
62
63
| Guide | Contents |
64
|---|---|
65
| [Simple Functions](references/simple-functions.md) | Simple Functions |
66
| [Stored Procedures](references/stored-procedures.md) | Stored Procedures |
67
| [Simple Procedures](references/simple-procedures.md) | Simple Procedures |
68
| [Complex Procedures with Error Handling](references/complex-procedures-with-error-handling.md) | Complex Procedures with Error Handling |
69
| [PostgreSQL Triggers](references/postgresql-triggers.md) | PostgreSQL Triggers |
70
| [MySQL Triggers](references/mysql-triggers.md) | MySQL Triggers |
71
72
## Best Practices
73
74
### ✅ DO
75
76
- Follow established patterns and conventions
77
- Write clean, maintainable code
78
- Add appropriate documentation
79
- Test thoroughly before deploying
80
81
### ❌ DON'T
82
83
- Skip testing or validation
84
- Ignore error handling
85
- Hard-code configuration values
86

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…