Re: Fw: Clipping values - Mailing list pgsql-general

From Tom Lane
Subject Re: Fw: Clipping values
Date
Msg-id 23671.1269448828@sss.pgh.pa.us
Whole thread Raw
In response to Fw: Clipping values  (Ovid <curtis_ovid_poe@yahoo.com>)
Responses Re: Fw: Clipping values  (Ovid <curtis_ovid_poe@yahoo.com>)
List pgsql-general
Ovid <curtis_ovid_poe@yahoo.com> writes:
> I have a table with four values which are constantly lowered by user action. These four values must rise over time,
infive minute intervals.  The core of the function, in pseudo-code, would look something like this: 

>   FOREACH row IN SELECT * FROM some_table WHERE some_percentages are less than 1
>   LOOP
>       new_percentage = num_intervals * .1 > 1
>           ? 1
>           : num_intervals * .1;
>       UPDATE some_table SET some_percentages = new_percentage WHERE id = row.id
>   END LOOP

> But, of course, doing that for four percentages (with at least one having a different increment value than .1)

You could code that directly with CASE operations, but it would probably
be easier to use GREATEST/LEAST, along the lines of
    new_percentage = LEAST(num_intervals * .1, 1);

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Revoking CREATE TABLE
Next
From: "Tony Webb"
Date:
Subject: Re: Revoking CREATE TABLE