How can I get a column INT4 to be UNSIGNED ?

Started by Bruno Baguettealmost 23 years ago10 messagesgeneral
Jump to latest
#1Bruno Baguette
bruno.baguette@netcourrier.com

Hello,

I would like to get a column of INT4, but instead having a range of
allowed values from -2147483648 to 2147483647, i would to get an
UNSIGNED range from 0 to 4294967295...

So, is it possible to create a column with an UNSIGNED INT4 type ? If
the answer is yes : what is the right syntax because I don't find the
right syntax to do that... :-/

Thanks a lot in advance for your help ! :-)

------------------------------------------------
Bruno BAGUETTE - bruno.baguette@netcourrier.com

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruno Baguette (#1)
Re: How can I get a column INT4 to be UNSIGNED ?

"Bruno Baguette" <bruno.baguette@netcourrier.com> writes:

So, is it possible to create a column with an UNSIGNED INT4 type ?

No.

You could use OID, which just happens to be 4 bytes unsigned. But a
cleaner approach IMHO would be to use int8 and put a CHECK constraint
on it to limit the range of values.

regards, tom lane

#3Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Tom Lane (#2)
Re: How can I get a column INT4 to be UNSIGNED ?

On Fri, Apr 11, 2003 at 10:05:49AM -0400, Tom Lane wrote:

"Bruno Baguette" <bruno.baguette@netcourrier.com> writes:

So, is it possible to create a column with an UNSIGNED INT4 type ?

No.

Is there a reason for not supporting unsigned types?

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Before you were born your parents weren't as boring as they are now. They
got that way paying your bills, cleaning up your room and listening to you
tell them how idealistic you are." -- Charles J. Sykes' advice to teenagers

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#3)
Re: How can I get a column INT4 to be UNSIGNED ?

Alvaro Herrera <alvherre@dcc.uchile.cl> writes:

Is there a reason for not supporting unsigned types?

Other than "it's not in any SQL standard", you mean?

Right now I'd resist adding such types because the numeric type
resolution rules are already a hairy mess. If we ever get those
straightened out to the point where unadorned constants are reliably
interpreted "the right way", we could take another look to see if
unsigned types could be added without plunging everything back into
chaos. I wouldn't hold my breath for it though.

regards, tom lane

#5Kyle
kyle@ccidomain.com
In reply to: Bruno Baguette (#1)
Re: How can I get a column INT4 to be UNSIGNED ?

Is there a reason for not supporting unsigned types?

Maybe I'm off base here, but couldn't you put in a constraint to achieve
the same effect? In other words require inserted data in that column to
be > -1 ?

-Kyle

#6scott.marlowe
scott.marlowe@ihs.com
In reply to: Tom Lane (#4)
Re: How can I get a column INT4 to be UNSIGNED ?

On Fri, 11 Apr 2003, Tom Lane wrote:

Alvaro Herrera <alvherre@dcc.uchile.cl> writes:

Is there a reason for not supporting unsigned types?

Other than "it's not in any SQL standard", you mean?

Right now I'd resist adding such types because the numeric type
resolution rules are already a hairy mess. If we ever get those
straightened out to the point where unadorned constants are reliably
interpreted "the right way", we could take another look to see if
unsigned types could be added without plunging everything back into
chaos. I wouldn't hold my breath for it though.

Actually, I think unsigned ints are mentioned all through the sql 92 docs,
but only as an underlying subtype, never as its own, isn't it?

#7Dennis Gearon
gearond@cvc.net
In reply to: Kyle (#5)
Re: How can I get a column INT4 to be UNSIGNED ?

If he wants the full range of an INT4 unsigned, he needs to go to INT8 with the
constraint you mentioned. The underlying col type of INT4 only supports HALF of
the range of an INT4 unsigned, in the positive domain, that is.

Kyle wrote:

Show quoted text

Is there a reason for not supporting unsigned types?

Maybe I'm off base here, but couldn't you put in a constraint to achieve
the same effect? In other words require inserted data in that column to
be > -1 ?

-Kyle

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

#8Ron Johnson
ron.l.johnson@cox.net
In reply to: Dennis Gearon (#7)
Re: How can I get a column INT4 to be UNSIGNED ?

On Fri, 2003-04-11 at 16:09, Dennis Gearon wrote:

If he wants the full range of an INT4 unsigned, he needs to go to INT8 with the
constraint you mentioned. The underlying col type of INT4 only supports HALF of
the range of an INT4 unsigned, in the positive domain, that is.

When domains allow CHECK constraints, that would be simplified, wouldn't
it?

-- 
+----------------------------------------------------------------+
| Ron Johnson, Jr.        mailto:ron.l.johnson@cox.net           |
| Jefferson, LA  USA      http://members.cox.net/ron.l.johnson   |
|                                                                |
| "A C program is like a fast dance on a newly waxed dance floor |
|  by people carrying razors."                                   |
|      Waldi Ravens                                              |
+----------------------------------------------------------------+
#9Bruce Momjian
bruce@momjian.us
In reply to: Ron Johnson (#8)
Re: How can I get a column INT4 to be UNSIGNED ?

Ron Johnson wrote:

On Fri, 2003-04-11 at 16:09, Dennis Gearon wrote:

If he wants the full range of an INT4 unsigned, he needs to go to INT8 with the
constraint you mentioned. The underlying col type of INT4 only supports HALF of
the range of an INT4 unsigned, in the positive domain, that is.

When domains allow CHECK constraints, that would be simplified, wouldn't
it?

I thought we did support it:

test=> CREATE DOMAIN unsigned AS int4 CHECK ( VALUE > 0);
CREATE DOMAIN

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#9)
Re: How can I get a column INT4 to be UNSIGNED ?

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Ron Johnson wrote:

When domains allow CHECK constraints, that would be simplified, wouldn't
it?

I thought we did support it:

test=> CREATE DOMAIN unsigned AS int4 CHECK ( VALUE > 0);
CREATE DOMAIN

It's new for 7.4, though.

regards, tom lane