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
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend