Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5331135

Browse files
committed
Rule deparser needs to quote identifiers that are spelled the same as
SQL keywords.
1 parent7657bce commit5331135

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
*
@@ -48,6 +48,7 @@
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
boolsafe;
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
returnident;/* no change needed */
17961812

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp