* 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.
*
#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"
{
/*
* 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;
}
}
+ 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 */