Skip to content

fabriziomello/unique_id

Repository files navigation

unique_id

PostgreSQL extension that implements non-Standard Time-based K-sorted, Lexicographically Unique Identifiers.

The inspiration to implement this PostgreSQL extension came from this github gist (PT-BR) that explains the differences between the usage of UUID and INT/BIGINT datatypes in RDBMS. This great material was written and is maintained by my friend Rafael Ponte.

Supported PostgreSQL versions

The aim of the project is support as many community-supported major versions of Postgres as possible. Currently, the following versions of PostgreSQL are supported:

10, 11, 12, 13 and master (pre-14).

Currently supported Unique Identifiers

Installation

$ git clone https://github.com/fabriziomello/unique_id.git
$ cd unique_id
# Make sure your path includes the bin directory that contains the correct `pg_config`
$ PATH=/path/to/pg/bin:$PATH
$ USE_PGXS=1 make
$ USE_PGXS=1 make install

Tests

$ USE_PGXS=1 make installcheck

Examples

fabrizio=# CREATE EXTENSION unique_id;
CREATE EXTENSION
fabrizio=# \dx unique_id
                                     List of installed extensions
   Name    | Version | Schema |                              Description                               
-----------+---------+--------+------------------------------------------------------------------------
 unique_id | 1.0     | public | Non-Standard Time-based K-sorted, Lexicographically Unique Identifiers
(1 row)

fabrizio=# CREATE SEQUENCE instagram_seq;
CREATE SEQUENCE
fabrizio=# -- Using default shard_id = 0
fabrizio=# SELECT unique_id_instagram('instagram_seq');
 unique_id_instagram 
---------------------
 2563729919292997633
(1 row)

fabrizio=# -- Using default shard_id = 1
fabrizio=# SELECT unique_id_instagram('instagram_seq', 1);
 unique_id_instagram 
---------------------
 2563729919292998658
(1 row)

Please feel free to open a PR.

Authors

License

PostgreSQL server source code, used under the PostgreSQL license.
Portions Copyright (c) 1996-2021, The PostgreSQL Global Development Group
Portions Copyright (c) 1994, The Regents of the University of California

All other parts are licensed under the 3-clause BSD license, see LICENSE file for details.
Copyright (c) 2021, Fabrízio de Royes Mello fabriziomello@gmail.com

About

PostgreSQL extension that implements non-Standard Time-based K-sorted, Lexicographically Unique Identifiers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published