Add options to force quoting of all identifiers.
I've added a quote_all_identifiers GUC which affects the behavior of the backend, and a --quote-all-identifiers argument to pg_dump and pg_dumpall which sets the GUC and also affects the quoting done internally by those applications. Design by Tom Lane; review by Alex Hunsaker; in response to bug #5488 filed by Hartmut Goebel.
This commit is contained in:
parent
b8c6c71d1c
commit
ce68df468a
|
@ -1,4 +1,4 @@
|
||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.298 2010/07/20 00:47:52 rhaas Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.299 2010/07/22 01:22:32 rhaas Exp $ -->
|
||||||
|
|
||||||
<chapter Id="runtime-config">
|
<chapter Id="runtime-config">
|
||||||
<title>Server Configuration</title>
|
<title>Server Configuration</title>
|
||||||
|
@ -5209,6 +5209,23 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry id="guc-quote-all-identifiers" xreflabel="quote-all-identifiers">
|
||||||
|
<term><varname>quote_all_identifiers</varname> (<type>boolean</type>)</term>
|
||||||
|
<indexterm>
|
||||||
|
<primary><varname>quote_all_identifiers</> configuration parameter</primary>
|
||||||
|
</indexterm>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
When the database generates SQL, force all identifiers to be quoted,
|
||||||
|
even if they are not (currently) keywords. This will affect the
|
||||||
|
output of <command>EXPLAIN</> as well as the results of functions
|
||||||
|
like <function>pg_get_viewdef</>. See also the
|
||||||
|
<option>--quote-all-identifiers</option> to
|
||||||
|
<xref linkend="app-pgdump"> and <xref linkend="app-pg-dumpall">.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry id="guc-sql-inheritance" xreflabel="sql_inheritance">
|
<varlistentry id="guc-sql-inheritance" xreflabel="sql_inheritance">
|
||||||
<term><varname>sql_inheritance</varname> (<type>boolean</type>)</term>
|
<term><varname>sql_inheritance</varname> (<type>boolean</type>)</term>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.117 2010/02/23 17:28:09 tgl Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.118 2010/07/22 01:22:33 rhaas Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -660,6 +660,17 @@ PostgreSQL documentation
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--quote-all-identifiers</></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Force quoting of all identifiers. This may be useful when dumping a
|
||||||
|
database for migration to a future version that may have introduced
|
||||||
|
additional keywords.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-?</></term>
|
<term><option>-?</></term>
|
||||||
<term><option>--help</></term>
|
<term><option>--help</></term>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.82 2010/04/03 07:23:01 petere Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.83 2010/07/22 01:22:33 rhaas Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -356,6 +356,17 @@ PostgreSQL documentation
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--quote-all-identifiers</></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Force quoting of all identifiers. This may be useful when dumping a
|
||||||
|
database for migration to a future version that may have introduced
|
||||||
|
additional keywords.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-?</></term>
|
<term><option>-?</></term>
|
||||||
<term><option>--help</></term>
|
<term><option>--help</></term>
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.328 2010/07/13 20:57:19 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.329 2010/07/22 01:22:33 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -132,6 +132,7 @@ static SPIPlanPtr plan_getrulebyoid = NULL;
|
||||||
static const char *query_getrulebyoid = "SELECT * FROM pg_catalog.pg_rewrite WHERE oid = $1";
|
static const char *query_getrulebyoid = "SELECT * FROM pg_catalog.pg_rewrite WHERE oid = $1";
|
||||||
static SPIPlanPtr plan_getviewrule = NULL;
|
static SPIPlanPtr plan_getviewrule = NULL;
|
||||||
static const char *query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2";
|
static const char *query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2";
|
||||||
|
bool quote_all_identifiers;
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
|
@ -6727,6 +6728,9 @@ quote_identifier(const char *ident)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quote_all_identifiers)
|
||||||
|
safe = false;
|
||||||
|
|
||||||
if (safe)
|
if (safe)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.564 2010/07/20 00:47:53 rhaas Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.565 2010/07/22 01:22:33 rhaas Exp $
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------
|
*--------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1282,6 +1282,15 @@ static struct config_bool ConfigureNamesBool[] =
|
||||||
false, NULL, NULL
|
false, NULL, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
{"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
|
||||||
|
gettext_noop("When generating SQL fragments, quote all identifiers."),
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
|
"e_all_identifiers,
|
||||||
|
false, NULL, NULL
|
||||||
|
},
|
||||||
|
|
||||||
/* End-of-list marker */
|
/* End-of-list marker */
|
||||||
{
|
{
|
||||||
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
|
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
|
||||||
|
|
|
@ -510,6 +510,7 @@
|
||||||
#default_with_oids = off
|
#default_with_oids = off
|
||||||
#escape_string_warning = on
|
#escape_string_warning = on
|
||||||
#lo_compat_privileges = off
|
#lo_compat_privileges = off
|
||||||
|
#quote_all_identifiers = off
|
||||||
#sql_inheritance = on
|
#sql_inheritance = on
|
||||||
#standard_conforming_strings = on
|
#standard_conforming_strings = on
|
||||||
#synchronize_seqscans = on
|
#synchronize_seqscans = on
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.56 2010/03/03 20:10:48 heikki Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.57 2010/07/22 01:22:34 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,8 @@ static bool parallel_init_done = false;
|
||||||
static DWORD tls_index;
|
static DWORD tls_index;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int quote_all_identifiers;
|
||||||
|
|
||||||
void
|
void
|
||||||
init_parallel_dump_utils(void)
|
init_parallel_dump_utils(void)
|
||||||
{
|
{
|
||||||
|
@ -102,8 +104,10 @@ fmtId(const char *rawid)
|
||||||
* These checks need to match the identifier production in scan.l. Don't
|
* These checks need to match the identifier production in scan.l. Don't
|
||||||
* use islower() etc.
|
* use islower() etc.
|
||||||
*/
|
*/
|
||||||
|
if (quote_all_identifiers)
|
||||||
|
need_quotes = true;
|
||||||
/* slightly different rules for first character */
|
/* slightly different rules for first character */
|
||||||
if (!((rawid[0] >= 'a' && rawid[0] <= 'z') || rawid[0] == '_'))
|
else if (!((rawid[0] >= 'a' && rawid[0] <= 'z') || rawid[0] == '_'))
|
||||||
need_quotes = true;
|
need_quotes = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.29 2010/02/26 02:01:16 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.30 2010/07/22 01:22:34 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -46,4 +46,6 @@ extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
|
||||||
const char *schemavar, const char *namevar,
|
const char *schemavar, const char *namevar,
|
||||||
const char *altnamevar, const char *visibilityrule);
|
const char *altnamevar, const char *visibilityrule);
|
||||||
|
|
||||||
|
extern int quote_all_identifiers;
|
||||||
|
|
||||||
#endif /* DUMPUTILS_H */
|
#endif /* DUMPUTILS_H */
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
* http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
|
* http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.582 2010/07/14 21:21:08 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.583 2010/07/22 01:22:34 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -297,6 +297,7 @@ main(int argc, char **argv)
|
||||||
{"inserts", no_argument, &dump_inserts, 1},
|
{"inserts", no_argument, &dump_inserts, 1},
|
||||||
{"lock-wait-timeout", required_argument, NULL, 2},
|
{"lock-wait-timeout", required_argument, NULL, 2},
|
||||||
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
|
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
|
||||||
|
{"quote-all-identifiers", no_argument, "e_all_identifiers, 1},
|
||||||
{"role", required_argument, NULL, 3},
|
{"role", required_argument, NULL, 3},
|
||||||
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
|
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
|
||||||
|
|
||||||
|
@ -634,6 +635,12 @@ main(int argc, char **argv)
|
||||||
if (g_fout->remoteVersion >= 70300)
|
if (g_fout->remoteVersion >= 70300)
|
||||||
do_sql_command(g_conn, "SET statement_timeout = 0");
|
do_sql_command(g_conn, "SET statement_timeout = 0");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Quote all identifiers, if requested.
|
||||||
|
*/
|
||||||
|
if (quote_all_identifiers && g_fout->remoteVersion >= 90100)
|
||||||
|
do_sql_command(g_conn, "SET quote_all_identifiers = true");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start serializable transaction to dump consistent data.
|
* Start serializable transaction to dump consistent data.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.134 2010/02/26 02:01:17 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.135 2010/07/22 01:22:34 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -130,6 +130,7 @@ main(int argc, char *argv[])
|
||||||
{"inserts", no_argument, &inserts, 1},
|
{"inserts", no_argument, &inserts, 1},
|
||||||
{"lock-wait-timeout", required_argument, NULL, 2},
|
{"lock-wait-timeout", required_argument, NULL, 2},
|
||||||
{"no-tablespaces", no_argument, &no_tablespaces, 1},
|
{"no-tablespaces", no_argument, &no_tablespaces, 1},
|
||||||
|
{"quote-all-identifiers", no_argument, "e_all_identifiers, 1},
|
||||||
{"role", required_argument, NULL, 3},
|
{"role", required_argument, NULL, 3},
|
||||||
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
|
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
|
||||||
|
|
||||||
|
@ -328,6 +329,8 @@ main(int argc, char *argv[])
|
||||||
appendPQExpBuffer(pgdumpopts, " --inserts");
|
appendPQExpBuffer(pgdumpopts, " --inserts");
|
||||||
if (no_tablespaces)
|
if (no_tablespaces)
|
||||||
appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
|
appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
|
||||||
|
if (quote_all_identifiers)
|
||||||
|
appendPQExpBuffer(pgdumpopts, " --quote-all-identifiers");
|
||||||
if (use_setsessauth)
|
if (use_setsessauth)
|
||||||
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
|
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
|
||||||
|
|
||||||
|
@ -440,6 +443,10 @@ main(int argc, char *argv[])
|
||||||
destroyPQExpBuffer(query);
|
destroyPQExpBuffer(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Force quoting of all identifiers if requested. */
|
||||||
|
if (quote_all_identifiers && server_version >= 90000)
|
||||||
|
executeCommand(conn, "SET quote_all_identifiers = true");
|
||||||
|
|
||||||
fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n");
|
fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n");
|
||||||
if (verbose)
|
if (verbose)
|
||||||
dumpTimestamp("Started on");
|
dumpTimestamp("Started on");
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.351 2010/07/13 20:57:19 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.352 2010/07/22 01:22:35 rhaas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -583,6 +583,7 @@ extern Datum record_ge(PG_FUNCTION_ARGS);
|
||||||
extern Datum btrecordcmp(PG_FUNCTION_ARGS);
|
extern Datum btrecordcmp(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
/* ruleutils.c */
|
/* ruleutils.c */
|
||||||
|
extern bool quote_all_identifiers;
|
||||||
extern Datum pg_get_ruledef(PG_FUNCTION_ARGS);
|
extern Datum pg_get_ruledef(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS);
|
extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_get_viewdef(PG_FUNCTION_ARGS);
|
extern Datum pg_get_viewdef(PG_FUNCTION_ARGS);
|
||||||
|
|
Loading…
Reference in New Issue