user-defined aggreaget functions

From: Karl DeBisschop <kdebisschop(at)spaceheater(dot)infoplease(dot)com>
To: pgsql-general(at)postgreSQL(dot)org
Subject: user-defined aggreaget functions
Date: 1999-04-14 19:07:24
Message-ID: 199904141907.PAA18580@skillet.infoplease.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


is it possible to use more than one user-defined aggregate function in
a single SELECT?

I have defined a function uid2int in pltcl to convert a string to an
integer representation.

CREATE FUNCTION uid2int4 (bpchar) RETURNS int4 AS '
regexp {([A-Z]*)0*([0-9]+)([A-Z]*)} $1 match pre num pst
if {"$pre" == "CE"} {return -$num}
scan $pre "%c" preint
set a [expr $preint - 64]
if {"$pst" != ""} {
scan $pst "%c" pstint
set z [expr $pstint - 64]
set a [expr 100 * $a]
return [expr $num + ($a+$z) * 10000000]
}
return [expr $num + $a * 10000000]
' LANGUAGE 'pltcl';

The function works fine in the statement

=> SELECT uid2int(uid),ipd from rhd;

but fails in

=> SELECT uid2int(uid),uid2int(ipd) from rhd;
ERROR: pltcl: can't read "pre": no such variable

where both uid and ipd are char(8).

Is there a simple and general way to avoid this problem?

--
Karl DeBisschop <kdebisschop(at)spaceheater(dot)infoplease(dot)com>
617.832.0332 (Fax: 617.956.2696)

Information Please - your source for FREE online reference
http://www.infoplease.com - Your Ultimate Fact Finder
http://kids.infoplease.com - The Great Homework Helper

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karl DeBisschop 1999-04-14 19:29:25 Re: [GENERAL] user-defined aggreaget functions
Previous Message José Soares 1999-04-14 15:39:34 Re: [GENERAL] Re: [HACKERS] Gregorian Calendar