Re: [PATCHES] Warning for missing createlang

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [PATCHES] Warning for missing createlang
Дата
Msg-id 200309051557.h85FvQw04854@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [PATCHES] Warning for missing createlang  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [PATCHES] Warning for missing createlang  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
> > Bruce Momjian wrote:
> >>> HINT:  Perhaps you need to use 'createlang' to load the language into
> >>> the database, or you mistyped the language name.
>
> > Why not list out the languages we *do* know about, and tell them it's
> > not in the list? Or is that too much work?
>
> Seems like it would clutter the error message without really addressing
> Bruce's concern.  I doubt that seeing the list of available languages
> would do much to jog a newbie's memory about needing to run createlang.
>
> We could answer my objection about the hint popping out on misspelled
> language names if the code were to arrange to put out the hint only when
> the language name is one of "plpgsql", "pltcl", "pltclu", etc.  This
> would have to use a hard-coded list of loadable language names, since
> by definition looking in pg_language won't help.  It would be enough of
> a maintenance PITA that I don't especially want to do it ... but it
> would ensure that the hint is likely to be relevant.

OK, new output is:

    test=> create function xx() returns int as '
    test'> select 1'
    test-> language 'plpgsql';
    ERROR:  language "plpgsql" does not exist
    HINT:  You need to use 'createlang' to load the language into the database.
    test=> create function xx() returns int as '
    test'> select 1'
    test-> language 'XXplpgsql';
    ERROR:  language "xxplpgsql" does not exist

Patch attached.

--
  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    5 Sep 2003 15:56:57 -0000
***************
*** 435,444 ****
                                     PointerGetDatum(languageName),
                                     0, 0, 0);
      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);

--- 435,458 ----
                                     PointerGetDatum(languageName),
                                     0, 0, 0);
      if (!HeapTupleIsValid(languageTuple))
!     {
!         /* Add any new languages to this list to invoke the hint. */
!         if (strcmp(languageName, "plperl") != 0 &&
!             strcmp(languageName, "plpgsql") != 0 &&
!             strcmp(languageName, "plpython") != 0 &&
!             strcmp(languageName, "plr") != 0 &&
!             strcmp(languageName, "plsh") != 0 &&
!             strcmp(languageName, "pltcl") != 0)
!             ereport(ERROR,
!                     (errcode(ERRCODE_UNDEFINED_OBJECT),
!                      errmsg("language \"%s\" does not exist", languageName)));
!         else
!             ereport(ERROR,
!                     (errcode(ERRCODE_UNDEFINED_OBJECT),
!                      errmsg("language \"%s\" does not exist", languageName),
!                      errhint("You need to use 'createlang' to load the language into the database.")));
!     }
!
      languageOid = HeapTupleGetOid(languageTuple);
      languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Czuczy Gergely
Дата:
Сообщение: Logging improvements and rehashing
Следующее
От: "scott.marlowe"
Дата:
Сообщение: Re: Seqscan in MAX(index_column)