If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > can DECIMAL columns be unsigned

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-26-09, 13:46
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
can DECIMAL columns be unsigned

Can DECIMAL columns be unsigned?
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
  #2 (permalink)  
Old 03-26-09, 15:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
not in ANSI SQL

were you thinking of perhaps a specific database system?
Code:
CREATE TABLE test_unsigned_decimal
( foo DECIMAL(9,3) UNSIGNED
);
INSERT INTO test_unsigned_decimal VALUES  
 ( 9.37 ) , ( +1.23 ), ( -4.56 )
;
SELECT * 
  FROM test_unsigned_decimal
;
the above works quite nicely in mysql

before testing it for yourself, see if you can guess what the stored values will be

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-26-09, 18:57
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Check constraints can prevent signed values.
Triggers can be used to remove any sign from the value.
You can store signed values and display them as unsigned with a simple query.
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 03-26-09, 21:46
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
guess

Well, I'll guess that they'll all be positive. But, I suspect a trick. Maybe the value with the + sign will be negative?

I can see where unsigned decimals would be problematic. I don't plan to use them but noticed no one (in the books I have) had explicitly said they did or didn't function.

Now I'll test it.
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
  #5 (permalink)  
Old 03-26-09, 23:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
textbooks that tried to cover all the stuff you can't do would be quite thick

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 03-27-09, 11:35
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
thick like my head

I got my own little error message. In all seriousness, thanks for the patience and the help. And... I'll probably need more help before long. But, for now, I'm rollin'.
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
  #7 (permalink)  
Old 03-27-09, 12:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
Quote:
Originally Posted by rbfree
Well, I'll guess that they'll all be positive. But, I suspect a trick. Maybe the value with the + sign will be negative?
no they won't, not really a trick, and no it won't, respectively

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 03-27-09, 13:17
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
Yes, the error message told me I can't insert the negative value. So, that's good to know, kind of. It means I have to go back and insert "unsigned" column constraints on a bunch of columns if I want to be fussy... which I do.
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
  #9 (permalink)  
Old 03-27-09, 13:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
Quote:
Originally Posted by rbfree
Yes, the error message told me I can't insert the negative value.
srsly?

not when i tested it (see above) --
Code:
foo
9.37
1.23
0
i'm on 4.1.20, what version gave you the error message?
Attached Thumbnails
can DECIMAL columns be unsigned-srsly.gif  
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 03-27-09, 14:04
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
yep

5.1.32

I really do like the image of the ... ostrich? Poignant. (Will you send me a jpg?)

I've attached a screenshot.

I supposed that means that we can enforce unsigned values in mysql (current).
Attached Thumbnails
can DECIMAL columns be unsigned-screenshot.jpg  
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On