aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-12-06 02:37:17 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-12-06 02:37:17 +0000
commit53311358c2ef777ac1122f9699ba505b60e65fa0 (patch)
tree7613cc35d4acf554452a2f1dd82b763bd9bd77a6 /src/backend/utils/adt/ruleutils.c
parent7657bce7a05302be3a3bb3e70012e8d02160c016 (diff)
downloadpostgresql-53311358c2ef777ac1122f9699ba505b60e65fa0.tar.gz
postgresql-53311358c2ef777ac1122f9699ba505b60e65fa0.zip
Rule deparser needs to quote identifiers that are spelled the same as
SQL keywords.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index a4f182770b9..b62559ccdde 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
* out of it's tuple
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.33 1999/11/24 16:52:37 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.34 1999/12/06 02:37:17 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -48,6 +48,7 @@
#include "lib/stringinfo.h"
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
+#include "parser/keywords.h"
#include "parser/parsetree.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
@@ -1764,8 +1765,8 @@ quote_identifier(char *ident)
{
/*
* Can avoid quoting if ident starts with a lowercase letter and
- * contains only lowercase letters, digits, and underscores.
- * Otherwise, supply quotes.
+ * contains only lowercase letters, digits, and underscores,
+ * *and* is not any SQL keyword. Otherwise, supply quotes.
*/
bool safe;
char *result;
@@ -1792,6 +1793,21 @@ quote_identifier(char *ident)
}
if (safe)
+ {
+ /*
+ * Check for keyword. This test is overly strong, since many of
+ * the "keywords" known to the parser are usable as column names,
+ * but the parser doesn't provide any easy way to test for whether
+ * an identifier is safe or not... so be safe not sorry.
+ *
+ * Note: ScanKeywordLookup() expects an all-lower-case input, but
+ * we've already checked we have that.
+ */
+ if (ScanKeywordLookup(ident) != NULL)
+ safe = false;
+ }
+
+ if (safe)
return ident; /* no change needed */
result = (char *) palloc(strlen(ident) + 2 + 1);