Contents
Example schema
Six tables cover every relation kind the generator handles. Each edge on the diagram carries its generated pair: blue arrow — the lookup, orange arrow — the list.
What the schema exercises:
- 1:1 —
profile_detail.profile_idis both PK and FK, so the list side collapses to a singular:profile_detail(profile). - Plain 1:N —
address.profile_id:profile(address)/address_list(profile). - Two FKs to one table —
document.client_idanddocument.manager_idboth point atprofile: lookups split by role (client(document),manager(document)), lists get role prefixes (client_document_list,manager_document_list).manager_idis nullable — the optional-relation case. - FK to a UNIQUE column, not the PK —
client_id/manager_idreference generated unique columns ofprofile. - Composite FK —
document (delivery_address_id, client_id)referencesaddress (id, profile_id):delivery_address(document)/document_list(address). - m:n bridge —
document_itemlinks documents and items: two lookups plusdocument_item_list(document)anddocument_item_list(item)— same name, different argument type, plain overloading. - Self-reference —
item.parent_item_id:parent_item(item)/item_list(item).
Files:
- init.sql — tables and seed data. Load it, run the generator, and all 16 relation functions appear.
- query.sql — 19 side-by-side pairs: classic joins vs relation functions, from simple lookups to recursion, DML and set operations.
No install needed to try it — the same schema with pre-generated functions lives in a db<>fiddle sandbox; the test environment adds bulk data for plan comparisons.