Thread

  1. how do you call one pltcl function from another?

    Jonathan Ellis <jellis@advocast.com> — 2000-11-06T15:29:07Z

    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?
    
    -Jonathan
    
    
    
    
  2. Re: how do you call one pltcl function from another?

    Jan Wieck <janwieck@yahoo.com> — 2000-11-08T09:56:46Z

    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 #
    
    
    
    
  3. Re: how do you call one pltcl function from another?

    Jonathan Ellis <jellis@advocast.com> — 2000-11-08T16:21:14Z

    >     You need to call it via SPI like
    >
    >         spi_exec "select meta_class($1) as retval"
    >         return $retval
    
    What kind of performance hit is there doing this vs two plpgsql functions?
    IIANM, you're creating two separate tcl interpreters this way, which seems
    expensive.
    
    -Jonathan
    
    
    
  4. Re: how do you call one pltcl function from another?

    Jan Wieck <janwieck@yahoo.com> — 2000-11-09T14:22:34Z

    Jonathan Ellis wrote:
    > >     You need to call it via SPI like
    > >
    > >         spi_exec "select meta_class($1) as retval"
    > >         return $retval
    >
    > What kind of performance hit is there doing this vs two plpgsql functions?
    > IIANM, you're creating two separate tcl interpreters this way, which seems
    > expensive.
    
        You  are  actually calling the same interpreter again through
        the SPI interface  (parser,  planner,  optimizer,  executor).
        Really expensive.
    
        Someone  can  skip  anything  but the executor by preparing a
        saved plan, but that's still a waste of  CPU.   At  the  very
        least,  calling  one  function from the other is expensive in
        any procedural language, that must  use  a  general  solution
        because the called function could be defined in any language.
    
    
    Jan
    
    --
    
    #======================================================================#
    # It's easier to get forgiveness for being wrong than for being right. #
    # Let's break this rule - forgive me.                                  #
    #================================================== JanWieck@Yahoo.com #