citusdata/pg_intpair

Name: pg_intpair

Owner: Citus Data

Description: null

Created: 2017-11-20 18:57:45.0

Updated: 2018-04-28 00:05:36.0

Pushed: 2018-03-06 08:24:49.0

Homepage: null

Size: 12

Language: C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

pg_intpair

This PostgreSQL extensions provides a single datatype named int64pair. It is simply a pair of 64-bit integers packed. In the absence of this extension, one could use PostgreSQL's composite types or arrays for the same purpose. The advantages of using int64pair are more performance and better storage density.

Usage
Migrating from a matching composite type

Suppose you already have a composite type with the following definition:

TE TYPE my_composite_type AS (first BIGINT, second BIGINT);

You can use the following `ALTER TABLEcommand to convert a column with the composite type to ``int64pair```:

R TABLE t ALTER COLUMN col TYPE int64pair USING a::text::int64pair;

You can enable implicit casting by defining following casts:

TE CAST (my_composite_type AS int64pair) WITH INOUT AS IMPLICIT;
TE CAST (int64pair AS my_composite_type) WITH INOUT AS IMPLICIT;

Then, you can do the previous `ALTER TABLEcolumn without the ``USING``` clause:

R TABLE t ALTER COLUMN col TYPE int64pair;

To be able to use the same `(col).firstand ``(col).second` syntax forint64pair`` columns, you can create couple of simple functions:

TE FUNCTION first(p int64pair) RETURNS BIGINT
AS 'select p[0];'
LANGUAGE SQL IMMUTABLE
RETURNS NULL ON NULL INPUT;

TE FUNCTION second(p int64pair) RETURNS BIGINT
AS 'select p[1];'
LANGUAGE SQL IMMUTABLE
RETURNS NULL ON NULL INPUT;

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.