Обсуждение: user-defined aggreaget functions

Поиск
Список
Период
Сортировка

user-defined aggreaget functions

От
Karl DeBisschop
Дата:
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

Re: [GENERAL] user-defined aggreaget functions

От
Karl DeBisschop
Дата:
Oops - Stupid mistake.

I thought i had filtered put all of the nulls and blank entries
from the source table, but I hadn't.  Of course the match doesn't work
on a blank entry.

the user-defined aggregate functions do work properly, and as
expected.  Sorry to trouble everyone.

--
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