Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 24ac52c

Browse files
committed
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.
1 parent b951c03 commit 24ac52c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.572 2010/02/18 01:29:10 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.573 2010/02/24 01:57:16 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -32,7 +32,6 @@
3232

3333
#include "access/attnum.h"
3434
#include "access/sysattr.h"
35-
#include "access/transam.h"
3635
#include "catalog/pg_cast.h"
3736
#include "catalog/pg_class.h"
3837
#include "catalog/pg_default_acl.h"
@@ -4795,10 +4794,8 @@ getProcLangs(int *numProcLangs)
47954794
"(%s lanowner) AS lanowner "
47964795
"FROM pg_language "
47974796
"WHERE lanispl "
4798-
/* do not dump initdb-installed languages */
4799-
"AND oid >= %u "
48004797
"ORDER BY oid",
4801-
username_subquery, FirstNormalObjectId);
4798+
username_subquery);
48024799
}
48034800
else if (g_fout->remoteVersion >= 80300)
48044801
{
@@ -4808,10 +4805,9 @@ getProcLangs(int *numProcLangs)
48084805
"lanvalidator, lanacl, "
48094806
"(%s lanowner) AS lanowner "
48104807
"FROM pg_language "
4811-
"WHERE lanispl%s "
4808+
"WHERE lanispl "
48124809
"ORDER BY oid",
4813-
username_subquery,
4814-
binary_upgrade ? "\nAND lanname != 'plpgsql'" : "");
4810+
username_subquery);
48154811
}
48164812
else if (g_fout->remoteVersion >= 80100)
48174813
{
@@ -7552,11 +7548,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
75527548
appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n",
75537549
qlanname);
75547550

7555-
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s",
7556-
(useParams && plang->lanpltrusted) ? "TRUSTED " : "",
7557-
qlanname);
75587551
if (useParams)
75597552
{
7553+
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s",
7554+
plang->lanpltrusted ? "TRUSTED " : "",
7555+
qlanname);
75607556
appendPQExpBuffer(defqry, " HANDLER %s",
75617557
fmtId(funcInfo->dobj.name));
75627558
if (OidIsValid(plang->laninline))
@@ -7580,6 +7576,20 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
75807576
fmtId(validatorInfo->dobj.name));
75817577
}
75827578
}
7579+
else
7580+
{
7581+
/*
7582+
* If not dumping parameters, then use CREATE OR REPLACE so that
7583+
* the command will not fail if the language is preinstalled in the
7584+
* target database. We restrict the use of REPLACE to this case so
7585+
* as to eliminate the risk of replacing a language with incompatible
7586+
* parameter settings: this command will only succeed at all if there
7587+
* is a pg_pltemplate entry, and if there is one, the existing entry
7588+
* must match it too.
7589+
*/
7590+
appendPQExpBuffer(defqry, "CREATE OR REPLACE PROCEDURAL LANGUAGE %s",
7591+
qlanname);
7592+
}
75837593
appendPQExpBuffer(defqry, ";\n");
75847594

75857595
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,

0 commit comments

Comments
 (0)