Unix Technical Forum

numeric data type

This is a discussion on numeric data type within the pgsql Novice forums, part of the PostgreSQL category; --> I've got the following: cc_exp_month numeric(2,0) So that I could input '06', for instance -- however the 0 doesn't ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 11:18 PM
Corey
 
Posts: n/a
Default numeric data type


I've got the following:

cc_exp_month numeric(2,0)


So that I could input '06', for instance -- however the 0 doesn't make it's
way into the column... I get '6' instead.

I want to constrain this in the db, which is why I don't just use:

cc_exp_month integer


My question: what do I need to do to have the constraint ( two digits ) work,
while still keeping the extra 0?


Thanks.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 11:18 PM
Richard Broersma Jr
 
Posts: n/a
Default Re: numeric data type


--- Corey <corey@bitworthy.net> wrote:

>
> I've got the following:
>
> cc_exp_month numeric(2,0)
>
>
> So that I could input '06', for instance -- however the 0 doesn't make it's
> way into the column... I get '6' instead.
>
> I want to constrain this in the db, which is why I don't just use:
>
> cc_exp_month integer
>
>
> My question: what do I need to do to have the constraint ( two digits ) work,
> while still keeping the extra 0?


I guess that you will have to use char or varchar is you "want" to have 0 infront of 6. However,
if you want it to actually be a numeric, then you will need to use some kind of formatting to
display all 0-9 as 00-09 when you select records from this table.

Regards,

Richard Broersma Jr.



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 11:18 PM
Phillip Smith
 
Posts: n/a
Default Re: numeric data type

Numeric and Integer type are exactly that - numbers.

If you want to _store_ it in the data with the leading 0, then you need to
change the type to a varchar, then put a check constraint on the field to
ensure that each of the 2 characters are numeric.

Alternatively, you can leave it as a numeric / integer and add the leading 0
as part of the queries that access it. Let me know if you want an example
how to do it.

Cheers,
-p

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailtogsql-novice-owner@postgresql.org] On Behalf Of Corey
Sent: Friday, 17 November 2006 2:14 AM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] numeric data type


I've got the following:

cc_exp_month numeric(2,0)


So that I could input '06', for instance -- however the 0 doesn't make it's
way into the column... I get '6' instead.

I want to constrain this in the db, which is why I don't just use:

cc_exp_month integer


My question: what do I need to do to have the constraint ( two digits )
work,
while still keeping the extra 0?


Thanks.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com