From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | jeff sacksteder <jsacksteder(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: unsigned types |
Date: | 2005-10-15 21:50:50 |
Message-ID: | BD0F1C1F-ED1E-45BD-BFD9-3AEE720595AB@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Oct 16, 2005, at 5:42 , jeff sacksteder wrote:
> It occurs to me that I don't know how to define unsigned integer
> datatypes. I'm making a schema to describe network packets and I
> need columns to contain values from 0-255, etc.
>
> I can't seem to find any documentation on this. What's the best
> prectice for this situation?
PostgreSQL does not have native unsigned integer datatypes. (For
reasons why, check the archives.) You can use domains or check
constraints to enforce a non-negative constraint. For example:
create table foo (
foo_id serial not null unique
, foo_unsigned_int integer not null check (foo_unsigned_int > 0)
);
or
create created domain unsigned_integer
as integer
check (value > 0);
create table bar (
bar_id serial not null unique
, bar_unsigned_int unsigned_integer not null
);
Here are doc references:
[check constraints](http://www.postgresql.org/docs/8.0/interactive/
ddl-constraints.html#AEN1936)
[create domain](http://www.postgresql.org/docs/8.0/interactive/sql-
createdomain.html)
Hope this helps.
Michael Glaesemann
grzm myrealbox com
From | Date | Subject | |
---|---|---|---|
Next Message | Neil Conway | 2005-10-15 22:02:55 | Re: unsigned types |
Previous Message | jeff sacksteder | 2005-10-15 20:42:36 | unsigned types |