Re: unsigned types

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: jeff sacksteder <jsacksteder(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unsigned types
Date: 2005-10-16 07:18:27
Message-ID: 1726400907.20051016091827@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can create a new type based on int2 called uint2.
he input function should subtract 32768 and the output function should
add 32768. The result should be an int4 so that a number such as 40000
can be displayed. The storage space required would still only be an
int2. The actual value stored in the database will be between -32768
to +32767 but the values that will be visible will be 0 to 65535

It seems simple enough to create a type to do that, though I haven't
tried.

Sim

>>You can use a signed type with a CHECK constraint to restrict the
>>column's value to positive integers.

>The sign doesn't concern me. I am storing a value that is unsigned
>and 16 bits wide natively. I'll have to just use an int4 and waste
>twice the space I actually need.

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2005-10-16 09:03:52 new type question
Previous Message Sim Zacks 2005-10-16 06:34:28 Re: strange error