Re: function to operate on same fields, different records?

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
Subject: Re: function to operate on same fields, different records?
Date: 2001-03-31 06:17:46
Message-ID: 20010331001746.R31280@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Mar 30, 2001 at 06:34:45PM -0800, Eric G. Miller wrote:
> On Fri, Mar 30, 2001 at 06:40:13PM -0600, will trillich wrote:
> > even using PLPGSQL, is it possible to send VARYING relation
> > tuples to a procedure/function -- so long as the attributes
> > (fields) munged within the function are common to all tables?
>
> Easiest way would be a five parameter function, then it doesn't need to
> know field names, just positions. I'm assuming you'll have a default of

fooey. i was hoping...

> zero for each grade field (simplifies NULL handling). An aggregate
> function might be more elegant (but certainly more work). Guess this
> school doesn't use the +/- modifiers?

only cosmetically. (a+,a,a- == 4.0)

> -- UNTESTED! Will accept any integer for a grade count...
>
> CREATE FUNCTION gpa (int4, int4, int4, int4, int4)
> -- "a" "b" "c" "d" "f"
> RETURNS float8 As '
> DECLARE
> numer float8 NOT NULL;
> denom int4 NOT NULL;

why NOT NULL ?

> BEGIN
> numer := 4.0 * $1 + 3.0 * $2 + 2.0 * $3 + 1.0 * $4;
> denom := $1 + $2 + $3 + $4 + $5;
>
> IF denom < 1 THEN
> RETURN 0.0;
> END IF;
>
> RETURN numer / denom;
> END;
> ' LANGUAGE 'plpgsql';

and here i had my hopes up for a universal "no record to big or
too small" function argument... thanks!

--
does a brain cell think?

will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2001-03-31 07:16:21 Re: Data access permission?
Previous Message will trillich 2001-03-31 06:13:28 Re: plperl -- postgresql married to perl