aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-06-18 21:40:58 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-06-18 21:40:58 +0000
commit4c310eca2eabce72e7346af4a539ed066cbabe3e (patch)
tree7f78874c9e9a6abe93a450f34991ba55fec8a43c /src/backend/utils/adt/ruleutils.c
parent532834081d9e9d482ff50becab86e014b5f1db30 (diff)
downloadpostgresql-4c310eca2eabce72e7346af4a539ed066cbabe3e.tar.gz
postgresql-4c310eca2eabce72e7346af4a539ed066cbabe3e.zip
Arrange for quote_identifier() and pg_dump to not quote keywords that are
unreserved according to the grammar. The list of unreserved words has gotten extensive enough that the unnecessary quoting is becoming a bit of an eyesore. To do this, add knowledge of the keyword category to keywords.c's table. (Someday we might be able to generate keywords.c's table and the keyword lists in gram.y from a common source.) For the moment, lie about WITH's status in the table so it will still get quoted --- this is because of the expectation that WITH will become reserved when the SQL recursive-queries patch gets done. I didn't force initdb because this affects nothing on-disk; but note that a few regression tests have changed expected output.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 49c7821cef0..df5dbec6078 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.261 2007/06/11 22:22:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.262 2007/06/18 21:40:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -5175,15 +5175,16 @@ quote_identifier(const 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.
+ * Check for keyword. We quote keywords except for unreserved ones.
+ * (In some cases we could avoid quoting a col_name or type_func_name
+ * keyword, but it seems much harder than it's worth to tell that.)
*
* Note: ScanKeywordLookup() does case-insensitive comparison, but
* that's fine, since we already know we have all-lower-case.
*/
- if (ScanKeywordLookup(ident) != NULL)
+ const ScanKeyword *keyword = ScanKeywordLookup(ident);
+
+ if (keyword != NULL && keyword->category != UNRESERVED_KEYWORD)
safe = false;
}