?
Solved

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

Posted on 2007-11-22
4
Medium Priority
?
217 Views
Last Modified: 2012-06-27
is there a possibility to have a columns that receives only values between  0 and 100?
0
Comment
Question by:toshi_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 20333792
   Hi!


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

Regards,
   Tomas Helgi
0
 

Author Comment

by:toshi_
ID: 20334205
ok, but i'd like to control that values are not higher than 100, and not negatives.
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 2000 total points
ID: 20334266
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
 

Author Comment

by:toshi_
ID: 20334345
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Debug Tools to analyse IIS process: This article focus on taking memory dumps from IIS to determine which code is taking more time and to analyse which calls hangs/causes more CPU usage. To take dumps,download the following. Install1: To st…
Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question