Re: how do you call one pltcl function from another? - Mailing list pgsql-general

From Jan Wieck
Subject Re: how do you call one pltcl function from another?
Date
Msg-id 200011080956.EAA07041@jupiter.jw.home
Whole thread Raw
In response to how do you call one pltcl function from another?  ("Jonathan Ellis" <jellis@advocast.com>)
List pgsql-general
Jonathan Ellis wrote:
> I tried mailing this last week, but I think it didn't get sent:
>
> I defined a procedure
>
> CREATE FUNCTION meta_class (varchar) RETURNS varchar AS '
> ...
> ' LANGUAGE 'pltcl';
>
> This works fine.  But when I want to call it from another tcl procedure I
> get errors:
> bf2=# CREATE FUNCTION foo (varchar) RETURNS varchar AS '
>     return [meta_class $1]
> ' LANGUAGE 'pltcl';
>
> bf2'# bf2'# CREATE
>
> bf2=# bf2=# select foo(class) from weapon_Types;
> ERROR:  pltcl: invalid command name "meta_class"
>
> This IS possible -- isn't it?

    It  is.  The problem is that the internal name of the proc in
    the Tcl interpreter doesn't have  to  do  with  the  function
    name.   Due   to   possible  function  overloading  (multiple
    functions with same name but  different  arguments)  this  is
    impossible.

    You need to call it via SPI like

        spi_exec "select meta_class($1) as retval"
        return $retval


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



pgsql-general by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Is cycle references?
Next
From: Michaël Fiey
Date:
Subject: Re: PGBUFFERS