calculate_markup
calculate_markup · C function that calculates a price markup percentage by linear interpolation over a numeric price/markup array.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100520 | calculate_markup | calculate_markup | 1.0 | FUNC | Unknown | C |
Usage
Sources:
calculate_markup installs the strict, immutable C function price_modifiers._calculate_markup(numeric, numeric[]). It selects or linearly interpolates a markup from a two-dimensional array of (price, markup) rows.
Core Workflow
Pass rows in descending price order. Prices above the first breakpoint use its markup, prices below the last breakpoint use the last markup, and values between breakpoints are interpolated and rounded to two decimal places.
The real SQL name begins with an underscore. Two README examples use price_modifiers.c_calculate_markup, but version 1.0 does not create that function.
Constraints and Safety
The implementation checks only that the array has two dimensions. It assumes exactly two values per row, descending and distinct price breakpoints, at least one row, and no NULL elements. It does not correctly inspect PostgreSQL’s NULL bitmap, and malformed, empty, odd-shaped, duplicate, or unsorted arrays can produce wrong results, division by zero, out-of-bounds access, or a backend crash. Validate the complete array shape and contents before calling it and test boundary prices explicitly.
This archived project has no current PostgreSQL compatibility statement. Treat it as unsafe native code, isolate evaluation in a disposable database, and prefer a small SQL implementation with explicit constraints for production pricing rules.