fbsql
fbsql : Closure-preserving formula-based statistical modeling in SQL
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| ----d-- | No | No | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | fbsql |
| Requires | plr |
| See Also | weighted_statistics pg_math vasco xicor |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.0 |
18 17 16 15 14 | fbsql |
plr |
| RPM | PIGSTY | 0.1.0 |
18 17 16 15 14 | fbsql_$v |
plr_$v |
| DEB | PIGSTY | 0.1.0 |
18 17 16 15 14 | postgresql-$v-fbsql |
postgresql-$v-plr |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| el8.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| el9.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| el9.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| el10.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| el10.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| d12.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| d12.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| d13.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| d13.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u22.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u22.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u24.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u24.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u26.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
| u26.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A | N/A |
Source
github.com/dsc-chiba-u/FbSQL
fbsql-0.1.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
fbsql is a proof-of-concept statistical-modeling DSL that keeps fitting and prediction relational: SQL queries go in and rows come back, while models are described with R formula syntax. Release 0.1.0 implements generalized linear models through PL/R for fitting and pure PL/pgSQL for prediction.
Prerequisites
FbSQL was developed and tested with PostgreSQL 16 and requires PL/R 8.4.0 or newer plus R. plr is an untrusted language, so a superuser must install the dependency and extension.
Grant regular users only the function access and source-data privileges they require.
Core Workflow
Fit a binomial churn model and retain the returned relation:
Prediction accepts a query for new rows and a query returning the saved model. Because it returns SETOF record, supply the output columns at the call site:
Important Objects
fbsql.fit_glm(relation, formula, family)returns one row per model term, repeated fit statistics, andmetadata jsonbcontaining the information needed for prediction.fbsql.predict_glm(relation, model, on_new_levels)appends<response>_predictedto the input rows.on_new_levelsiserrorby default ornato produce a null prediction for unseen factor levels.fbsql.version()reports the extension version.
Supported Surface and Caveats
Version 0.1.0 supports Gaussian models with the identity link and binomial models with the logit link, using numeric and factor predictors. Fitting applies complete-case analysis and reports used and dropped row counts; prediction returns NULL when a predictor is null. Prediction uses stored coefficients and metadata and does not invoke R at runtime.
Interactions, custom contrasts, offsets, weights, prediction intervals, additional families and links, and distributed fitting are not supported. The relation and model parameters contain SQL text: construct them from trusted SQL, not unsanitized user input, and review the executing role’s privileges.