77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
99 * IDENTIFICATION
10- * $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.77 2008/03/27 03:57:33 tgl Exp $
10+ * $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.78 2008/04/29 19:37:04 alvherre Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -50,6 +50,8 @@ typedef struct
5050static void create_proc_lang (const char * languageName ,
5151Oid languageOwner ,Oid handlerOid ,Oid valOid ,bool trusted );
5252static PLTemplate * find_language_template (const char * languageName );
53+ static void AlterLanguageOwner_internal (HeapTuple tup ,Relation rel ,
54+ Oid newOwnerId );
5355
5456
5557/* ---------------------------------------------------------------------
@@ -528,7 +530,6 @@ AlterLanguageOwner(const char *name, Oid newOwnerId)
528530{
529531HeapTuple tup ;
530532Relation rel ;
531- Form_pg_language lanForm ;
532533
533534/* Translate name for consistency with CREATE */
534535name = case_translate_language_name (name );
@@ -542,6 +543,47 @@ AlterLanguageOwner(const char *name, Oid newOwnerId)
542543ereport (ERROR ,
543544(errcode (ERRCODE_UNDEFINED_OBJECT ),
544545errmsg ("language \"%s\" does not exist" ,name )));
546+
547+ AlterLanguageOwner_internal (tup ,rel ,newOwnerId );
548+
549+ ReleaseSysCache (tup );
550+
551+ heap_close (rel ,RowExclusiveLock );
552+
553+ }
554+
555+ /*
556+ * Change language owner, specified by OID
557+ */
558+ void
559+ AlterLanguageOwner_oid (Oid oid ,Oid newOwnerId )
560+ {
561+ HeapTuple tup ;
562+ Relation rel ;
563+
564+ rel = heap_open (LanguageRelationId ,RowExclusiveLock );
565+
566+ tup = SearchSysCache (LANGOID ,
567+ ObjectIdGetDatum (oid ),
568+ 0 ,0 ,0 );
569+ if (!HeapTupleIsValid (tup ))
570+ elog (ERROR ,"cache lookup failed for language %u" ,oid );
571+
572+ AlterLanguageOwner_internal (tup ,rel ,newOwnerId );
573+
574+ ReleaseSysCache (tup );
575+
576+ heap_close (rel ,RowExclusiveLock );
577+ }
578+
579+ /*
580+ * Workhorse for AlterLanguageOwner variants
581+ */
582+ static void
583+ AlterLanguageOwner_internal (HeapTuple tup ,Relation rel ,Oid newOwnerId )
584+ {
585+ Form_pg_language lanForm ;
586+
545587lanForm = (Form_pg_language )GETSTRUCT (tup );
546588
547589/*
@@ -599,7 +641,4 @@ AlterLanguageOwner(const char *name, Oid newOwnerId)
599641changeDependencyOnOwner (LanguageRelationId ,HeapTupleGetOid (tup ),
600642newOwnerId );
601643}
602-
603- ReleaseSysCache (tup );
604- heap_close (rel ,RowExclusiveLock );
605644}