Re: Novice PL/pgSQL question and example - Mailing list pgsql-novice

From Tim Landscheidt
Subject Re: Novice PL/pgSQL question and example
Date
Msg-id m3r5ov8m19.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to Re: Novice PL/pgSQL question and example  (James Long <pgsql-novice@museum.rain.com>)
Responses Re: Novice PL/pgSQL question and example
List pgsql-novice
James Long <pgsql-novice@museum.rain.com> wrote:

> [...]
> Is that as good as this can get, or is there a simpler way, more
> along the lines of the first version?

I'm not certain that I get the gist of your share_costs ()
function, but why not just something functional along the
lines of:

| tim=# SELECT G.A, TRUNC(90.0 / 7, 2) +
| tim-#             CASE
| tim-#               WHEN ROW_NUMBER() OVER (ORDER BY G.A) <= 100 * (90 - 7 * TRUNC(90.0 / 7, 2)) THEN
| tim-#                 0.01
| tim-#               ELSE
| tim-#                 0.00
| tim-#               END
| tim-#   FROM generate_series(1, 7) AS G(A);
|  a | ?column?
| ---+----------
|  1 |    12.86
|  2 |    12.86
|  3 |    12.86
|  4 |    12.86
|  5 |    12.86
|  6 |    12.85
|  7 |    12.85
| (7 Zeilen)

| tim=#

Tim

pgsql-novice by date:

Previous
From: James Long
Date:
Subject: Re: Novice PL/pgSQL question and example
Next
From: James Long
Date:
Subject: Re: Novice PL/pgSQL question and example