Home > Mobile >  Is it possible to create a new datatype in postgresql as a range of values?
Is it possible to create a new datatype in postgresql as a range of values?

Time:03-05

What I want to do is declare a new type that is a range on numbers, something along the lines of:

CREATE TYPE mynumbers AS ENUM(generate_series(1,144,0.5));

Essentially I want to have a type mynumbers that will be the values between 1 to 144 in step increments of 0.5

CodePudding user response:

Use a domain:

CREATE DOMAIN mynumbers AS numeric
   CHECK (VALUE >= 1 AND VALUE <= 144
          AND trunc(VALUE * 2) = VALUE * 2);

Such a domain can be used like a data type in column definitions.

  • Related