pg_bikram_sambat

Bikram Sambat date type and AD/BS conversion functions

Overview

PackageVersionCategoryLicenseLanguage
pg_bikram_sambat0.1.0TYPEPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
3860pg_bikram_sambatNoYesNoYesNoYes-
Relatedpg_duration pg_rrule pgcalendar timestamp9 pg_extra_time periods temporal_tables country

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.1.01817161514pg_bikram_sambat-
RPMPIGSTY0.1.01817161514pg_bikram_sambat_$v-
DEBPIGSTY0.1.01817161514postgresql-$v-pg-bikram-sambat-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el8.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0

Build

You can build the RPM / DEB packages for pg_bikram_sambat using pig build:

pig build pkg pg_bikram_sambat         # build RPM / DEB packages

Install

You can install pg_bikram_sambat directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_bikram_sambat;          # Install for current active PG version
pig ext install -y pg_bikram_sambat -v 18  # PG 18
pig ext install -y pg_bikram_sambat -v 17  # PG 17
pig ext install -y pg_bikram_sambat -v 16  # PG 16
pig ext install -y pg_bikram_sambat -v 15  # PG 15
pig ext install -y pg_bikram_sambat -v 14  # PG 14
dnf install -y pg_bikram_sambat_18       # PG 18
dnf install -y pg_bikram_sambat_17       # PG 17
dnf install -y pg_bikram_sambat_16       # PG 16
dnf install -y pg_bikram_sambat_15       # PG 15
dnf install -y pg_bikram_sambat_14       # PG 14
apt install -y postgresql-18-pg-bikram-sambat   # PG 18
apt install -y postgresql-17-pg-bikram-sambat   # PG 17
apt install -y postgresql-16-pg-bikram-sambat   # PG 16
apt install -y postgresql-15-pg-bikram-sambat   # PG 15
apt install -y postgresql-14-pg-bikram-sambat   # PG 14

Create Extension:

CREATE EXTENSION pg_bikram_sambat;

Usage

Sources: PGXN metadata, PGXN source tree, type SQL, function SQL, operator SQL, cast SQL, regression examples, TODO

pg_bikram_sambat adds a bs_date type for Bikram Sambat dates plus conversion, formatting, comparison, and btree indexing support. Install it as a normal PostgreSQL extension:

CREATE EXTENSION pg_bikram_sambat;

Date Type

bs_date stores a Bikram Sambat date and displays it as YYYY-MM-DD. Text input accepts year/month/day values separated with /, -, or .; the input parser also accepts day-first strings when the year appears in the last field.

SELECT '2057/10/19'::bs_date;
SELECT CAST('2057-10-19' AS bs_date);
SELECT '19.10.2057'::bs_date;

Use it in tables like any other PostgreSQL type:

CREATE TABLE events (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  ad_date date,
  bs bs_date NOT NULL
);

INSERT INTO events (ad_date, bs)
VALUES
  ('2001-02-01', '2057/10/19'),
  ('1972-02-17', '2028/11/05');

Conversion Functions

ad_to_bs(date) converts a Gregorian date to bs_date:

SELECT ad_to_bs('2001-02-01'::date);  -- 2057-10-19
SELECT ad_to_bs('1972-02-17'::date);  -- 2028-11-05

current_bs_date() returns the current transaction timestamp converted to bs_date, so repeated calls inside the same transaction are stable:

SELECT current_bs_date();
SELECT pg_typeof(current_bs_date());  -- bs_date

Version 0.1.0 does not expose a SQL bs_to_ad() function or direct bs_date to date cast; the upstream TODO file lists those as future work.

Formatting

The extension overloads PostgreSQL to_char for bs_date:

SELECT to_char('2057/10/19'::bs_date, 'YYYY-MM-DD');
SELECT to_char('2057/10/19'::bs_date, 'DD/MM/YYYY');
SELECT to_char('2057/10/19'::bs_date, 'Month DD, YYYY');
SELECT to_char('2057/10/19'::bs_date, 'Day, DD Month YYYY');

Supported date-format tokens are YYYY, YY, Month, Mon, MM, Day, Dy, and DD. Month and weekday names follow the casing of the format token, so MONTH, Month, and month produce upper-case, title-case, and lower-case English names.

Pass dev as the third argument for Devanagari digits, month names, and weekday names:

SELECT to_char('2057/10/19'::bs_date, 'YYYY-MM-DD', 'dev');
SELECT to_char('2057/10/19'::bs_date, 'Day, DD Month YYYY', 'dev');

Operators And Indexes

bs_date supports the comparison operators =, <>, >, >=, <, and <=. The default btree operator class bs_date_ops enables ordinary btree indexes, range predicates, and ordering:

CREATE INDEX events_bs_idx ON events (bs);

SELECT * FROM events WHERE bs >= '2057/01/01' ORDER BY bs;
SELECT * FROM events WHERE bs BETWEEN '2056/01/01' AND '2058/12/12';

Caveats

The packaged conversion dataset covers BS years 2000 through 2100, with 1943-04-14 AD as the reference date for 2000-01-01 BS. Dates before the reference date or beyond the mapped BS range raise PostgreSQL errors. The extension defines an implicit cast from text to bs_date, but it does not define casts from arbitrary numeric types.


Last Modified 2026-05-01: update extension data (aaef844)