pg_ta
pg_ta · TA-Lib technical-analysis functions exposed as PostgreSQL functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100644 | pg_ta | pg_ta | 1.0 | FUNC | BSD-2-Clause | C |
Usage
Sources:
pg_ta is a 2014 proof of concept for calling TA-Lib from PostgreSQL. Version 1.0 exposes only ta_f(double precision[]), which returns a set representing a simple moving average with a hard-coded period of 5.
Core Workflow
Builds require the external TA-Lib headers and library. Array order defines observation order; PostgreSQL does not infer ordering from a source query. The first four returned rows are NULL because the five-value moving-average window is not yet complete.
The function rejects arrays containing NULL. There is no parameter for the period or TA-Lib moving-average type, and no other indicators are implemented.
Critical Safety Boundary
Do not execute this extension outside an isolated test instance. The reviewed C code allocates its PostgreSQL result array for TA-Lib’s shorter outNbElement count, then writes one entry for every input element. For a period of 5 this writes four Datum values beyond the allocation and can corrupt backend memory. It also treats a zero Datum as the NULL marker, so a real moving-average result of 0 can be emitted as SQL NULL.
Upstream explicitly says the code is experimental, unstable, and not for anything remotely close to production. The source predates current PostgreSQL and TA-Lib releases; even apparently correct sample output is not evidence of memory safety or compatibility.