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 */
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}
48034800else 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}
48164812else if (g_fout -> remoteVersion >=80100 )
48174813{
@@ -7552,11 +7548,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
75527548appendPQExpBuffer (delqry ,"DROP PROCEDURAL LANGUAGE %s;\n" ,
75537549qlanname );
75547550
7555- appendPQExpBuffer (defqry ,"CREATE %sPROCEDURAL LANGUAGE %s" ,
7556- (useParams && plang -> lanpltrusted ) ?"TRUSTED " :"" ,
7557- qlanname );
75587551if (useParams )
75597552{
7553+ appendPQExpBuffer (defqry ,"CREATE %sPROCEDURAL LANGUAGE %s" ,
7554+ plang -> lanpltrusted ?"TRUSTED " :"" ,
7555+ qlanname );
75607556appendPQExpBuffer (defqry ," HANDLER %s" ,
75617557fmtId (funcInfo -> dobj .name ));
75627558if (OidIsValid (plang -> laninline ))
@@ -7580,6 +7576,20 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
75807576fmtId (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+ }
75837593appendPQExpBuffer (defqry ,";\n" );
75847594
75857595ArchiveEntry (fout ,plang -> dobj .catId ,plang -> dobj .dumpId ,