Thread: Warning for missing createlang

Warning for missing createlang

From
Bruce Momjian
Date:
I have written a patch to issue an hint if someone tries to create a
function in a language that isn't loaded into the database:

    test=> CREATE FUNCTION xx() RETURNS INT AS '
    test'> select 1'
    test-> LANGUAGE 'plpgsql';
    ERROR:  language "plpgsql" does not exist
    HINT:  Perhaps you need to use 'createlang' to load the language into
    the database.

I know Peter didn't like this idea in the past, but we are getting too
many people who forget createlang, and with our new HINT tags, it seems
appropriate.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/commands/functioncmds.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/functioncmds.c,v
retrieving revision 1.33
diff -c -c -r1.33 functioncmds.c
*** src/backend/commands/functioncmds.c    4 Aug 2003 02:39:58 -0000    1.33
--- src/backend/commands/functioncmds.c    4 Sep 2003 23:08:06 -0000
***************
*** 437,443 ****
      if (!HeapTupleIsValid(languageTuple))
          ereport(ERROR,
                  (errcode(ERRCODE_UNDEFINED_OBJECT),
!                  errmsg("language \"%s\" does not exist", languageName)));

      languageOid = HeapTupleGetOid(languageTuple);
      languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
--- 437,444 ----
      if (!HeapTupleIsValid(languageTuple))
          ereport(ERROR,
                  (errcode(ERRCODE_UNDEFINED_OBJECT),
!                  errmsg("language \"%s\" does not exist", languageName),
!                  errhint("Perhaps you need to use 'createlang' to load the language into the database.")));

      languageOid = HeapTupleGetOid(languageTuple);
      languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);

Re: Warning for missing createlang

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> I have written a patch to issue an hint if someone tries to create a
> function in a language that isn't loaded into the database:

>     ERROR:  language "plpgsql" does not exist
>     HINT:  Perhaps you need to use 'createlang' to load the language into
>     the database.

> I know Peter didn't like this idea in the past, but we are getting too
> many people who forget createlang, and with our new HINT tags, it seems
> appropriate.

I still agree with Peter's opinion ... this hint is fairly silly,
especially since it would pop out for simple misspellings of language
names.

            regards, tom lane

Re: Warning for missing createlang

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I have written a patch to issue an hint if someone tries to create a
> > function in a language that isn't loaded into the database:
>
> >     ERROR:  language "plpgsql" does not exist
> >     HINT:  Perhaps you need to use 'createlang' to load the language into
> >     the database.
>
> > I know Peter didn't like this idea in the past, but we are getting too
> > many people who forget createlang, and with our new HINT tags, it seems
> > appropriate.
>
> I still agree with Peter's opinion ... this hint is fairly silly,
> especially since it would pop out for simple misspellings of language
> names.

What can we do to help people remember they have forgotten to load the
language?  The post that question here too often.  I don't see any
problem with a hint that starts with "Perhaps".

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Warning for missing createlang

From
Bruce Momjian
Date:
Bruce Momjian wrote:
> I have written a patch to issue an hint if someone tries to create a
> function in a language that isn't loaded into the database:
>
>     test=> CREATE FUNCTION xx() RETURNS INT AS '
>     test'> select 1'
>     test-> LANGUAGE 'plpgsql';
>     ERROR:  language "plpgsql" does not exist
>     HINT:  Perhaps you need to use 'createlang' to load the language into
>     the database.
>
> I know Peter didn't like this idea in the past, but we are getting too
> many people who forget createlang, and with our new HINT tags, it seems
> appropriate.

OK, Peter and Tom don't like it.  :-(

How about this, that also suggests you mistyped the name:

>     HINT:  Perhaps you need to use 'createlang' to load the language into
>     the database, or you mistyped the language name.

                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Warning for missing createlang

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> How about this, that also suggests you mistyped the name:
>
> >     HINT:  Perhaps you need to use 'createlang' to load the language into
> >     the database, or you mistyped the language name.

That's only one step away from this:

peter=# SELECT * FROM test;
ERROR:  relation "test" does not exist
HINT:  Perhaps you need to use "CREATE TABLE" to create the table in the
database, or you mistyped the table name.

I think not...

--
Peter Eisentraut   peter_e@gmx.net


Re: Warning for missing createlang

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > How about this, that also suggests you mistyped the name:
> >
> > >     HINT:  Perhaps you need to use 'createlang' to load the language into
> > >     the database, or you mistyped the language name.
>
> That's only one step away from this:
>
> peter=# SELECT * FROM test;
> ERROR:  relation "test" does not exist
> HINT:  Perhaps you need to use "CREATE TABLE" to create the table in the
> database, or you mistyped the table name.
>
> I think not...

I never suggested that.  Just because the extreme is wrong doesn't make
the case we are discussing wrong.

If the hint is useful, then we add it.  I don't see the above as useful,
while I see the CREATE FUCTION as useful.  No one is posting asking why
they have to create the table before selecting from it.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073