aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/crosstabview.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-04-17 11:37:58 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-04-17 11:37:58 -0400
commit9603a32594d2f5e6d9a1f098bc554a68f44ccb3c (patch)
treeedff5a29faf3ea1bf72f676cf0c82ec4afb84cf0 /src/bin/psql/crosstabview.c
parent4039c736eb0955cb1daf88e211f105dbbb78f7ea (diff)
downloadpostgresql-9603a32594d2f5e6d9a1f098bc554a68f44ccb3c.tar.gz
postgresql-9603a32594d2f5e6d9a1f098bc554a68f44ccb3c.zip
Avoid code duplication in \crosstabview.
In commit 6f0d6a507 I added a duplicate copy of psqlscanslash's identifier downcasing code, but actually it's not hard to split that out as a callable subroutine and avoid the duplication.
Diffstat (limited to 'src/bin/psql/crosstabview.c')
-rw-r--r--src/bin/psql/crosstabview.c30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c
index 71abaf3a6fe..7685c6e7467 100644
--- a/src/bin/psql/crosstabview.c
+++ b/src/bin/psql/crosstabview.c
@@ -12,6 +12,7 @@
#include "common.h"
#include "crosstabview.h"
#include "pqexpbuffer.h"
+#include "psqlscanslash.h"
#include "settings.h"
@@ -648,39 +649,14 @@ indexOfColumn(char *arg, const PGresult *res)
}
else
{
- bool inquotes = false;
- char *cp = arg;
int i;
/*
* Dequote and downcase the column name. By checking for all-digits
* before doing this, we can ensure that a quoted name is treated as a
- * name even if it's all digits. This transformation should match
- * what psqlscanslash.l does in OT_SQLID mode. (XXX ideally we would
- * let the lexer do this, but then we couldn't tell if the name was
- * quoted.)
+ * name even if it's all digits.
*/
- while (*cp)
- {
- if (*cp == '"')
- {
- if (inquotes && cp[1] == '"')
- {
- /* Keep the first quote, remove the second */
- cp++;
- }
- inquotes = !inquotes;
- /* Collapse out quote at *cp */
- memmove(cp, cp + 1, strlen(cp));
- /* do not advance cp */
- }
- else
- {
- if (!inquotes)
- *cp = pg_tolower((unsigned char) *cp);
- cp += PQmblen(cp, pset.encoding);
- }
- }
+ dequote_downcase_identifier(arg, true, pset.encoding);
/* Now look for match(es) among res' column names */
idx = -1;