quote_all_identifiers.patch
application/octet-stream
Filename: quote_all_identifiers.patch
Type: application/octet-stream
Part: 0
Message:
pg_dump(all) --quote-all-identifiers
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/ruleutils.c | 4 | 0 |
| src/backend/utils/misc/guc.c | 9 | 0 |
| src/bin/pg_dump/dumputils.c | 5 | 1 |
| src/bin/pg_dump/dumputils.h | 2 | 0 |
| src/bin/pg_dump/pg_dumpall.c | 9 | 0 |
| src/bin/pg_dump/pg_dump.c | 7 | 0 |
| src/include/utils/builtins.h | 1 | 0 |
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index b85eefa..278e105 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -125,6 +125,7 @@ static SPIPlanPtr plan_getrulebyoid = NULL;
static const char *query_getrulebyoid = "SELECT * FROM pg_catalog.pg_rewrite WHERE oid = $1";
static SPIPlanPtr plan_getviewrule = NULL;
static const char *query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2";
+bool quote_all_identifiers;
/* ----------
@@ -6473,6 +6474,9 @@ quote_identifier(const char *ident)
}
}
+ if (quote_all_identifiers)
+ safe = false;
+
if (safe)
{
/*
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6597e18..bf16e03 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1261,6 +1261,15 @@ static struct config_bool ConfigureNamesBool[] =
false, NULL, NULL
},
+ {
+ {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS,
+ gettext_noop("When generating SQL fragments, quote all identifiers."),
+ NULL,
+ },
+ "e_all_identifiers,
+ false, NULL, NULL
+ },
+
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index 4c5f9a5..3d26185 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -36,6 +36,8 @@ static bool parallel_init_done = false;
static DWORD tls_index;
#endif
+int quote_all_identifiers;
+
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
* use islower() etc.
*/
+ if (quote_all_identifiers)
+ need_quotes = true;
/* 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;
else
{
diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h
index 6762839..77d05d0 100644
--- a/src/bin/pg_dump/dumputils.h
+++ b/src/bin/pg_dump/dumputils.h
@@ -46,4 +46,6 @@ extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
const char *schemavar, const char *namevar,
const char *altnamevar, const char *visibilityrule);
+extern int quote_all_identifiers;
+
#endif /* DUMPUTILS_H */
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 1c4867d..471a246 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -297,6 +297,7 @@ main(int argc, char **argv)
{"inserts", no_argument, &dump_inserts, 1},
{"lock-wait-timeout", required_argument, NULL, 2},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
+ {"quote-all-identifiers", no_argument, "e_all_identifiers, 1},
{"role", required_argument, NULL, 3},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
@@ -635,6 +636,12 @@ main(int argc, char **argv)
do_sql_command(g_conn, "SET statement_timeout = 0");
/*
+ * Quote all identifiers, if requested.
+ */
+ if (quote_all_identifiers && g_fout->remoteVersion >= 90000)
+ do_sql_command(g_conn, "SET quote_all_identifiers = true");
+
+ /*
* Start serializable transaction to dump consistent data.
*/
do_sql_command(g_conn, "BEGIN");
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 0c3f63f..e0f0607 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -130,6 +130,7 @@ main(int argc, char *argv[])
{"inserts", no_argument, &inserts, 1},
{"lock-wait-timeout", required_argument, NULL, 2},
{"no-tablespaces", no_argument, &no_tablespaces, 1},
+ {"quote-all-identifiers", no_argument, "e_all_identifiers, 1},
{"role", required_argument, NULL, 3},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
@@ -328,6 +329,8 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " --inserts");
if (no_tablespaces)
appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
+ if (quote_all_identifiers)
+ appendPQExpBuffer(pgdumpopts, " --quote-all-identifiers");
if (use_setsessauth)
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
@@ -440,6 +443,12 @@ main(int argc, char *argv[])
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");
if (verbose)
dumpTimestamp("Started on");
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index ed64ebc..05bd5d8 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -583,6 +583,7 @@ extern Datum record_ge(PG_FUNCTION_ARGS);
extern Datum btrecordcmp(PG_FUNCTION_ARGS);
/* ruleutils.c */
+extern bool quote_all_identifiers;
extern Datum pg_get_ruledef(PG_FUNCTION_ARGS);
extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS);
extern Datum pg_get_viewdef(PG_FUNCTION_ARGS);