user-defined aggreaget functions - Mailing list pgsql-general

From Karl DeBisschop
Subject user-defined aggreaget functions
Date
Msg-id 199904141907.PAA18580@skillet.infoplease.com
Whole thread Raw
Responses Re: [GENERAL] user-defined aggreaget functions  (Karl DeBisschop <kdebisschop@spaceheater.infoplease.com>)
List 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@spaceheater.infoplease.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

pgsql-general by date:

Previous
From: José Soares
Date:
Subject: Re: [GENERAL] Re: [HACKERS] Gregorian Calendar
Next
From: Karl DeBisschop
Date:
Subject: Re: [GENERAL] user-defined aggreaget functions