PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2003, 03:32 PM
imind imind is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: mexico
Posts: 13 imind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 0
Help - How to define the UNSIGNED attribute

Hi everybody,
I am switching from mysql to postgresql 7.3 and I do not know how to define an unsigned int field .
Any pointers will be much appreciated!
Thanks

Reply With Quote
  #2  
Old January 28th, 2003, 04:17 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Postgres does NOT support unsigned values.
__________________
FSBO (For Sale By Owner) Realty

Reply With Quote
  #3  
Old January 28th, 2003, 05:24 PM
imind imind is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: mexico
Posts: 13 imind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 0
Thanks

I appreciate your response rod k. Now that I know better I wonder if modifying the system catalogs ( pg_cast, pg_type ) or making use of user defined types will make any sense.
I have some apps that I would like to port to postgres in order to take some burden of the applications' code needed to "grant" some data integrity to the db under mysql. I am going through the documentation and I am not sure I am getting anywhere. Should I give it a rest?
Thanks again

Reply With Quote
  #4  
Old January 28th, 2003, 05:50 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
You could define new datatypes for unsigned integer data (AND you'd have to define the operators for them, too). I doubt it's necessary tho. The only place it would be, is if you needed values > 2^63 and where you didn't need values > 2^64 which isn't very likely.

Reply With Quote
  #5  
Old January 28th, 2003, 10:03 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Rod K is right on the money, although I will offer a couple other suggestions:

1. If you are wanting to use the 'unsigned' attribute for data constraint purposes, you can simply define a CHECK constraint for any field that prohibits entering negative values.

2. If you are using PostgreSQL 7.3 or better, you can create a DOMAIN defining a named column with the above-mentioned CHECK constraint, so that domain can be used as an unsigned type anywhere in the database, without worrying about manually including the CHECK constraint everywhere.
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #6  
Old January 29th, 2003, 11:39 AM
imind imind is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: mexico
Posts: 13 imind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 0
Thanks guys, I feel that I am getting closer, I am certainly getting the feeling of what can be done. I appreciate your inputs. I still need to play with those 8th,16th,32nd bits so I will keep over this some more and post back any comments I had.

Reply With Quote
  #7  
Old January 29th, 2003, 12:04 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Quote:
I still need to play with those 8th,16th,32nd bits
Why?

Reply With Quote
  #8  
Old January 29th, 2003, 01:21 PM
imind imind is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: mexico
Posts: 13 imind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 0
Well, these are meaningfull bits for us. Must of the software we make deals with pos devices with older processors and bioses and apis designed for the state of the art at the time. So through time, we have developed code that deals with for example virtual decimal points in 16 or 32 bit data, or amounts represented by 2 32 bit ints, authentication code, etc. The missing unsigned attribute shakes the carpet under my feet since I forsee a deep review of code.
I admit, I might be totally lost, since I have intalled Postgres last week and that's the time I have been in touch with it.

The pointers you have made give me some grounds as to keep looking deeper. But still I think missing the unsigned attribute is somehow a "weakness" ( shoud be a better word ) since your int data is restricted to 31 bits and I understand there is a performance penalty in bigints - according to docs.

Reply With Quote
  #9  
Old January 29th, 2003, 05:43 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Quote:
I understand there is a performance penalty in bigints
Depends on the OS you are using.

I still don't see this as an issue. You are referring to legacy software that uses bit data, and are concerned that the DB does as well, yet you mention using MySQL integer types to store the data, which is also a translation from the original value.

You could do a couple of things. Convert the bit values to/from their twos complement (thereby safely converting int to/from the binary value), or use a FLOAT or NUMERIC (if float doesn't provide the precision you need).

Reply With Quote
  #10  
Old January 29th, 2003, 06:48 PM
imind imind is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: mexico
Posts: 13 imind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 0
Well, it can be done of course, but somehow it does not feel right. I’ll have to take a star from the product J ( still a great feature packed dbm , no doubt ) .

I think my main concern is the cost of switching - and probably more the cost of switching without solid knowledge of the db.

Suppose you have timestamps packed into 32 bit int data and you play with those. You ask the dbm to do something with those timestamps and then you, as they are, take them into your frontend and, as they are, you pass them to some other place. Yes you can still do it but it will need some care here and there. I don´t know, but to me this lack of the unsigned attribute felt a little like when you read in some product’s doc, “well you really don’t need subqueries since you can do this and this,,you don’t really need transactions or foreign keys since you can do this and this and this…”

Hey guys, really, I apprecite the time you gave to this issue. Thanks a lot.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Help - How to define the UNSIGNED attribute

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap