33 * out of it's tuple
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.33 1999/11/24 16:52:37 momjian Exp $
6+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.34 1999/12/06 02:37:17 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
4848#include "lib/stringinfo.h"
4949#include "optimizer/clauses.h"
5050#include "optimizer/tlist.h"
51+ #include "parser/keywords.h"
5152#include "parser/parsetree.h"
5253#include "utils/builtins.h"
5354#include "utils/lsyscache.h"
@@ -1764,8 +1765,8 @@ quote_identifier(char *ident)
17641765{
17651766 /*
17661767 * Can avoid quoting if ident starts with a lowercase letter and
1767- * contains only lowercase letters, digits, and underscores.
1768- * Otherwise, supply quotes.
1768+ * contains only lowercase letters, digits, and underscores,
1769+ * *and* is not any SQL keyword. Otherwise, supply quotes.
17691770 */
17701771 bool safe ;
17711772 char * result ;
@@ -1791,6 +1792,21 @@ quote_identifier(char *ident)
17911792 }
17921793 }
17931794
1795+ if (safe )
1796+ {
1797+ /*
1798+ * Check for keyword. This test is overly strong, since many of
1799+ * the "keywords" known to the parser are usable as column names,
1800+ * but the parser doesn't provide any easy way to test for whether
1801+ * an identifier is safe or not... so be safe not sorry.
1802+ *
1803+ * Note: ScanKeywordLookup() expects an all-lower-case input, but
1804+ * we've already checked we have that.
1805+ */
1806+ if (ScanKeywordLookup (ident ) != NULL )
1807+ safe = false;
1808+ }
1809+
17941810 if (safe )
17951811 return ident ; /* no change needed */
17961812
0 commit comments