pg_calcpi
pg_calcpi · Computes digits of pi in PostgreSQL with a PL/pgSQL spigot algorithm.
Overview
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pg_calcpi implements a PL/pgSQL spigot algorithm for digits of pi. calcpi(n) returns a set of the composite type digit, with a one-based sequence number and one decimal digit per row.
Each invocation creates and repeatedly updates a session-local working table, so runtime grows sharply with the requested digit count. This is educational code, not a numeric library or efficient workload for a shared database server.
The function first executes an unqualified DROP TABLE IF EXISTS calcpi_internal_data before creating its temporary table. If a caller can resolve a persistent table with that name and owns it, the call can drop that table. Use only in an isolated schema/database with a controlled search_path, and do not grant execution to untrusted roles.