Skip to content

pg_hlc

PostgreSQL HLC (Hybrid Logical Clock) extension in Rust compatible with Dart CRDT library.

pg_hlc · PostgreSQL HLC (Hybrid Logical Clock) extension in Rust compatible with Dart CRDT library.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101554pg_hlcpg_hlc0.1.0TYPEMITRust

Usage

Sources:

pg_hlc — A PostgreSQL extension (pg_hlc) that provides Hybrid Logical Clock (HLC) functionality with 100% compatibility with the Dart CRDT library. The extension is built using the pgrx framework and implements the exact same HLC algorithm and API as the Dart reference implementation. Use it when application data needs this type, domain, or its operators. Use the pinned upstream revision linked above as the API boundary and test it on the target PostgreSQL build.

Core Workflow

CREATE EXTENSION pg_hlc;

Install the extension in the intended database, run the smallest upstream example above when available, and verify the installed version and returned values before integrating it into application SQL.

Important Objects

  • hlc_compare(hlctimestamp, hlctimestamp) is an extension function and returns integer.
  • hlc_eq(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_from_date(text, text) is an extension function and returns hlctimestamp.
  • hlc_gt(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_gte(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_increment(text) is an extension function and returns hlctimestamp.
  • hlc_lt(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_lte(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_merge(text, hlctimestamp) is an extension function and returns hlctimestamp.
  • hlc_ne(hlctimestamp, hlctimestamp) is an extension function and returns boolean.
  • hlc_now(text) is an extension function and returns hlctimestamp.
  • hlc_parse(text) is an extension function and returns hlctimestamp.
  • hlc_reset(text) is an extension function and returns boolean.
  • hlc_to_string(hlctimestamp) is an extension function and returns text.

Requirements and Caveats

  • The catalog records version 0.1.0.
  • The control file marks the extension as non-relocatable.
  • The control file requires a superuser for installation.
  • The control file marks the extension as not trusted.
  • Confirm privileges, supported PostgreSQL versions, upgrade behavior, and failure cases against the pinned source before production use.

Table reader