Re: [PATCHES] Warning for missing createlang - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [PATCHES] Warning for missing createlang
Date
Msg-id 200309051718.h85HIoi20134@candle.pha.pa.us
Whole thread Raw
In response to Re: [PATCHES] Warning for missing createlang  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCHES] Warning for missing createlang
Re: [PATCHES] Warning for missing createlang
List pgsql-hackers
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> 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:
>
> You forgot pltclu, and I believe plpython is now called plpythonu, and
> I'm not sure whether there's a plperlu, and if you're going to include
> outside-the-distro languages then I am pretty sure there's a plruby.
> See what I mean about the maintenance headache this will cause?

I don't mind the maintenance.  I just want people to stop getting stuck
creating plpsql functions.  Frankly, I don't care if we only test for
plpgsql (the most common case).  It doesn't have to be perfect --- it
only prints a HINT.  I willing to put some imperfect code in there to
improve usability.

> BTW, duplicating the ereport is no fun.  I'd suggest the coding style
> used in some other places, with errhint called in a conditional
> expression:
>
>             ereport(ERROR,
>                     (errcode(ERRCODE_UNDEFINED_OBJECT),
>                      errmsg("language \"%s\" does not exist", languageName),
>              known_language(languageName) ?
>                      errhint("You need to use 'createlang' to load the language into the database.") : 0));
>
> where known_language() is a little subroutine that has the strcmp()s.

Here is the new output:

    test=> create function xx() returns int as '
    test'> select 1'
    test-> language 'XXplpgsql';
    ERROR:  language "xxplpgsql" does not exist
    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.

Why does the ': 0' work?  I didn't figure that would work, but it does.

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 17:08:48 -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,456 ----
                                     PointerGetDatum(languageName),
                                     0, 0, 0);
      if (!HeapTupleIsValid(languageTuple))
+         /* Add any new languages to this list to invoke the hint. */
          ereport(ERROR,
                  (errcode(ERRCODE_UNDEFINED_OBJECT),
!                  errmsg("language \"%s\" does not exist", languageName),
!                    (strcmp(languageName, "plperl") == 0 ||
!                     strcmp(languageName, "plperlu") == 0 ||
!                     strcmp(languageName, "plpgsql") == 0 ||
!                     strcmp(languageName, "plpython") == 0 ||
!                     strcmp(languageName, "plpythonu") == 0 ||
!                     strcmp(languageName, "plr") == 0 ||
!                     strcmp(languageName, "plruby") == 0 ||
!                     strcmp(languageName, "plsh") == 0 ||
!                     strcmp(languageName, "pltcl") == 0 ||
!                     strcmp(languageName, "pltclu") == 0) ?
!                  errhint("You need to use 'createlang' to load the language into the database.") : 0));
!
      languageOid = HeapTupleGetOid(languageTuple);
      languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Stats Collector Error 7.4beta1 and 7.4beta2
Next
From: Andrew Dunstan
Date:
Subject: Re: TCP/IP with 7.4 beta2 broken?