Code Monkey home page Code Monkey logo

pguint's Introduction

Unsigned and other extra integer types for PostgreSQL

This extension provides additional integer types for PostgreSQL:

  • int1 (signed 8-bit integer)
  • u8 (unsigned 8-bit integer)
  • u16 (unsigned 16-bit integer)
  • u32 (unsigned 32-bit integer)
  • u64 (unsigned 64-bit integer)

Installation

PostgreSQL version 9.1 or later is required. Currently, only 64-bit builds are supported.

To build and install this module:

make
make install

or selecting a specific PostgreSQL installation:

make PG_CONFIG=/some/where/bin/pg_config
make PG_CONFIG=/some/where/bin/pg_config install

And finally inside the database:

CREATE EXTENSION uint;

Using

You can use the new types like the standard integer types. Examples:

CREATE TABLE foo (
    a u32,
    b text
);

SELECT * FROM foo WHERE a > 4;

SELECT avg(a) FROM foo;

The types come with a sizable set of operators and functions, index support, etc. Some pieces are still missing, but they are being worked on. If there is anything you can't find, let me know.

Discussion

Support for unsigned integer types and smaller integer types has been one of the more common outstanding feature request for PostgreSQL. Inclusion of additional integer types into the core is typically rejected with the argument that it would make the type system too complicated and fragile. The experience from writing this module suggests: That is not wrong. Another argument, either explicit or implicit, is that it is a lot of work. Again: true.

The combination of the requirements of the SQL standard and the type system of PostgreSQL effectively create a situation where you need to provide a comprehensive set of operators and functions for each combination of numeric types. So for the three standard integer types, that's 9 "+" operators, 9 "<" operators, and so on. And with 3 + 5 = 8 types, well, you do the math. This module solves that problem by generating most of the code automatically.

The purpose of this module is therefore twofold: First, it should be useful in practice. There is no reason why it couldn't be. Second, it is a challenge to the PostgreSQL extension mechanism. In that area, there are various "interesting" problems that still need to be worked out.

Testing

In addition to the test suite of this module (make installcheck), it is useful to test this module by running the main PostgreSQL regression tests while this module is loaded, which should not fail. This will verify that the presence of the additional types and operators will not cause changes in the interpretation of expressions involving the existing types and operators.

pguint's People

Contributors

petere avatar proger10 avatar usrtax avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.