• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

is there a built-in type in postgres for a columns which can receive values in percent : 0-100?

is there a possibility to have a columns that receives only values between  0 and 100?
0
toshi_
Asked:
toshi_
  • 2
  • 2
1 Solution
 
Tomas Helgi JohannssonCommented:
   Hi!


Percentage is usually stored in a database either as an Integer value or as Float/Double value.

Regards,
   Tomas Helgi
0
 
toshi_Author Commented:
ok, but i'd like to control that values are not higher than 100, and not negatives.
0
 
Tomas Helgi JohannssonCommented:
WHen you create your table you can issue a check
like the attached code snippet shows

Regards,
  Tomas Helgi
postgres=# CREATE TABLE mytable (
postgres(#    nr integer,
postgres(#    percentige numeric,  CHECK (percentige > 0 and percentige <= 100)
postgres(# );
CREATE TABLE

Open in new window

0
 
toshi_Author Commented:
wonderful,
as i'm using pgAdminIII, i can add ckeck as constraints with graphical interface.
i never took notice of it.

thanks a lot.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now