aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql')
-rw-r--r--src/bin/psql/common.c7
-rw-r--r--src/bin/psql/variables.c26
-rw-r--r--src/bin/psql/variables.h1
3 files changed, 34 insertions, 0 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index ff673665d86..dfbc22970f8 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -786,6 +786,13 @@ StoreQueryTuple(const PGresult *result)
/* concatenate prefix and column name */
varname = psprintf("%s%s", pset.gset_prefix, colname);
+ if (VariableHasHook(pset.vars, varname))
+ {
+ pg_log_warning("attempt to \\gset into specially treated variable \"%s\" ignored",
+ varname);
+ continue;
+ }
+
if (!PQgetisnull(result, 0, i))
value = PQgetvalue(result, 0, i);
else
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c
index 52aa5e5f164..84349fc753f 100644
--- a/src/bin/psql/variables.c
+++ b/src/bin/psql/variables.c
@@ -361,6 +361,32 @@ SetVariableHooks(VariableSpace space, const char *name,
}
/*
+ * Return true iff the named variable has substitute and/or assign hook
+ * functions.
+ */
+bool
+VariableHasHook(VariableSpace space, const char *name)
+{
+ struct _variable *current;
+
+ Assert(space);
+ Assert(name);
+
+ for (current = space->next; current; current = current->next)
+ {
+ int cmp = strcmp(current->name, name);
+
+ if (cmp == 0)
+ return (current->substitute_hook != NULL ||
+ current->assign_hook != NULL);
+ if (cmp > 0)
+ break; /* it's not there */
+ }
+
+ return false;
+}
+
+/*
* Convenience function to set a variable's value to "on".
*/
bool
diff --git a/src/bin/psql/variables.h b/src/bin/psql/variables.h
index ab5e51f20b5..b932472021a 100644
--- a/src/bin/psql/variables.h
+++ b/src/bin/psql/variables.h
@@ -90,6 +90,7 @@ bool DeleteVariable(VariableSpace space, const char *name);
void SetVariableHooks(VariableSpace space, const char *name,
VariableSubstituteHook shook,
VariableAssignHook ahook);
+bool VariableHasHook(VariableSpace space, const char *name);
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions);