Thread: Problem with PL/pgSQL

Problem with PL/pgSQL

From
Hans-Jürgen Schönig
Date:
What is wrong with the following function?

CREATE FUNCTION logfunc2 (text) RETURNS int AS '
        DECLARE
                text ALIAS FOR $1;
        BEGIN
                SELECT length(text);
                RETURN ''3'';
        END;
' LANGUAGE 'plpgsql';

I get the following error:

ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.

        Recognized languages are sql, C, internal, and created
procedural languages.


According to my docs "plpgsql" should be ok.

    Hans


Re: Problem with PL/pgSQL

From
"Mitch Vincent"
Date:
You need to do

CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
    '/usr/local/pgsql/lib/plpgsql.so' LANGUAGE 'C';

And :

CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
    HANDLER plpgsql_call_handler
    LANCOMPILER 'PL/pgSQL';


----- Original Message -----
From: "Hans-Jürgen Schönig" <hs@cybertec.at>
To: <pgsql-general@postgresql.org>
Sent: Saturday, February 24, 2001 10:01 AM
Subject: Problem with PL/pgSQL


> What is wrong with the following function?
>
> CREATE FUNCTION logfunc2 (text) RETURNS int AS '
>         DECLARE
>                 text ALIAS FOR $1;
>         BEGIN
>                 SELECT length(text);
>                 RETURN ''3'';
>         END;
> ' LANGUAGE 'plpgsql';
>
> I get the following error:
>
> ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
>
>         Recognized languages are sql, C, internal, and created
> procedural languages.
>
>
> According to my docs "plpgsql" should be ok.
>
>     Hans
>
>


Re: Problem with PL/pgSQL

From
"Eric G. Miller"
Date:
On Sat, Feb 24, 2001 at 04:01:59PM +0100, Hans-Jürgen Schönig wrote:
> What is wrong with the following function?
>
> CREATE FUNCTION logfunc2 (text) RETURNS int AS '
>         DECLARE
>                 text ALIAS FOR $1;
>         BEGIN
>                 SELECT length(text);
>                 RETURN ''3'';
>         END;
> ' LANGUAGE 'plpgsql';

That won't work:

CREATE FUNCTION logfunc2 (text) RETURNS int4 AS '
    DECLARE
        phrase ALIAS FOR $1;  -- "text" is a reserved word
    BEGIN
        RETURN length (phrase);
    END;
' LANGUAGE 'plpgsql';

testbed# SELECT logfunc2('foobar');
 logfunc2
----------
        6
(1 row)

> I get the following error:
>
> ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
>
>         Recognized languages are sql, C, internal, and created
> procedural languages.

Maybe plpgsql is not "installed" into template1?

template1# SELECT * FROM pg_language;
 lanname  | lanispl | lanpltrusted | lanplcallfoid | lancompiler
----------+---------+--------------+---------------+-------------
 internal | f       | f            |             0 | n/a
 C        | f       | f            |             0 | /bin/cc
 sql      | f       | f            |             0 | postgres
 plpgsql  | t       | t            |         21024 | PL/pgSQL
 plperl   | t       | t            |        305959 | PL/Perl
(5 rows)

--
Eric G. Miller <egm2@jps.net>

Re: Problem with PL/pgSQL

From
Tom Lane
Date:
=?iso-8859-1?Q?Hans=2DJ=FCrgen=20Sch=F6nig?= <hs@cybertec.at> writes:
> I get the following error:
> ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.

You didn't run "createlang" to make plpgsql available in your database.
It's not installed by default.

            regards, tom lane

Re: Problem with PL/pgSQL

From
Ian Harding
Date:
Hans-Jürgen Schönig wrote:

> What is wrong with the following function?
>
> CREATE FUNCTION logfunc2 (text) RETURNS int AS '
>         DECLARE
>                 text ALIAS FOR $1;
>         BEGIN
>                 SELECT length(text);
>                 RETURN ''3'';
>         END;
> ' LANGUAGE 'plpgsql';
>
> I get the following error:
>
> ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
>
>         Recognized languages are sql, C, internal, and created
> procedural languages.
>
> According to my docs "plpgsql" should be ok.
>
>     Hans

plpgsql is not installed by default.

createlang 'plpgsql'

from the command line should to the trick.