Re: function to operate on same fields, different records? - Mailing list pgsql-general

From will trillich
Subject Re: function to operate on same fields, different records?
Date
Msg-id 20010331001746.R31280@mail.serensoft.com
Whole thread Raw
In response to Re: function to operate on same fields, different records?  ("Eric G. Miller" <egm2@jps.net>)
Responses Re: function to operate on same fields, different records?  ("Eric G. Miller" <egm2@jps.net>)
List 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@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: Re: plperl -- postgresql married to perl
Next
From: "Oliver Elphick"
Date:
Subject: Re: pg_hba.conf and crypt/password