mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
Use CREATE OR REPLACE LANGUAGE in pg_dump to avoid the need for a couple of
significantly uglier kluges that were working around the change in plpgsql's preinstalled status.
This commit is contained in:
parent
b951c03f88
commit
24ac52c3f1
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.572 2010/02/18 01:29:10 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.573 2010/02/24 01:57:16 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#include "access/attnum.h"
|
#include "access/attnum.h"
|
||||||
#include "access/sysattr.h"
|
#include "access/sysattr.h"
|
||||||
#include "access/transam.h"
|
|
||||||
#include "catalog/pg_cast.h"
|
#include "catalog/pg_cast.h"
|
||||||
#include "catalog/pg_class.h"
|
#include "catalog/pg_class.h"
|
||||||
#include "catalog/pg_default_acl.h"
|
#include "catalog/pg_default_acl.h"
|
||||||
@ -4795,10 +4794,8 @@ getProcLangs(int *numProcLangs)
|
|||||||
"(%s lanowner) AS lanowner "
|
"(%s lanowner) AS lanowner "
|
||||||
"FROM pg_language "
|
"FROM pg_language "
|
||||||
"WHERE lanispl "
|
"WHERE lanispl "
|
||||||
/* do not dump initdb-installed languages */
|
|
||||||
"AND oid >= %u "
|
|
||||||
"ORDER BY oid",
|
"ORDER BY oid",
|
||||||
username_subquery, FirstNormalObjectId);
|
username_subquery);
|
||||||
}
|
}
|
||||||
else if (g_fout->remoteVersion >= 80300)
|
else if (g_fout->remoteVersion >= 80300)
|
||||||
{
|
{
|
||||||
@ -4808,10 +4805,9 @@ getProcLangs(int *numProcLangs)
|
|||||||
"lanvalidator, lanacl, "
|
"lanvalidator, lanacl, "
|
||||||
"(%s lanowner) AS lanowner "
|
"(%s lanowner) AS lanowner "
|
||||||
"FROM pg_language "
|
"FROM pg_language "
|
||||||
"WHERE lanispl%s "
|
"WHERE lanispl "
|
||||||
"ORDER BY oid",
|
"ORDER BY oid",
|
||||||
username_subquery,
|
username_subquery);
|
||||||
binary_upgrade ? "\nAND lanname != 'plpgsql'" : "");
|
|
||||||
}
|
}
|
||||||
else if (g_fout->remoteVersion >= 80100)
|
else if (g_fout->remoteVersion >= 80100)
|
||||||
{
|
{
|
||||||
@ -7552,11 +7548,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
|
|||||||
appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n",
|
appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n",
|
||||||
qlanname);
|
qlanname);
|
||||||
|
|
||||||
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s",
|
|
||||||
(useParams && plang->lanpltrusted) ? "TRUSTED " : "",
|
|
||||||
qlanname);
|
|
||||||
if (useParams)
|
if (useParams)
|
||||||
{
|
{
|
||||||
|
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s",
|
||||||
|
plang->lanpltrusted ? "TRUSTED " : "",
|
||||||
|
qlanname);
|
||||||
appendPQExpBuffer(defqry, " HANDLER %s",
|
appendPQExpBuffer(defqry, " HANDLER %s",
|
||||||
fmtId(funcInfo->dobj.name));
|
fmtId(funcInfo->dobj.name));
|
||||||
if (OidIsValid(plang->laninline))
|
if (OidIsValid(plang->laninline))
|
||||||
@ -7580,6 +7576,20 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
|
|||||||
fmtId(validatorInfo->dobj.name));
|
fmtId(validatorInfo->dobj.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If not dumping parameters, then use CREATE OR REPLACE so that
|
||||||
|
* the command will not fail if the language is preinstalled in the
|
||||||
|
* target database. We restrict the use of REPLACE to this case so
|
||||||
|
* as to eliminate the risk of replacing a language with incompatible
|
||||||
|
* parameter settings: this command will only succeed at all if there
|
||||||
|
* is a pg_pltemplate entry, and if there is one, the existing entry
|
||||||
|
* must match it too.
|
||||||
|
*/
|
||||||
|
appendPQExpBuffer(defqry, "CREATE OR REPLACE PROCEDURAL LANGUAGE %s",
|
||||||
|
qlanname);
|
||||||
|
}
|
||||||
appendPQExpBuffer(defqry, ";\n");
|
appendPQExpBuffer(defqry, ";\n");
|
||||||
|
|
||||||
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
|
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user