Attached is a patch to allow the user to change the behavior of postgres with 
reguards to case sensitivity on unquoted identifiers.  This does not change 
the default behavior of converting unquoted identifiers to lowercase, but 
does allow (for instance, and I'm absolutly -not- pulling from personal 
experience here <g>) a large project to run under postgres that did run under 
MySQL a whole bunch easier.

for example, these two SQL statements sets are identical
set parser-ignore-case = false;
select "Address_id" from "Address";

set parser-ignore-case = true;
select Address_id from Address;
diff -Naur postgresql-8.0.0rc5/src/backend/parser/scansup.c postgresql-8.0.0rc5-new/src/backend/parser/scansup.c
--- postgresql-8.0.0rc5/src/backend/parser/scansup.c	Fri Dec 31 17:00:27 2004
+++ postgresql-8.0.0rc5-new/src/backend/parser/scansup.c	Fri Jan 14 13:44:05 2005
@@ -21,6 +21,7 @@
 #include "parser/scansup.h"
 #include "mb/pg_wchar.h"
 
+bool parser_ignore_case = true;
 
 /* ----------------
  *		scanstr
@@ -147,10 +148,11 @@
 	{
 		unsigned char ch = (unsigned char) ident[i];
 
-		if (ch >= 'A' && ch <= 'Z')
-			ch += 'a' - 'A';
-		else if (ch >= 0x80 && isupper(ch))
-			ch = tolower(ch);
+		if (parser_ignore_case)
+			if (ch >= 'A' && ch <= 'Z')
+				ch += 'a' - 'A';
+			else if (ch >= 0x80 && isupper(ch))
+				ch = tolower(ch);
 		result[i] = (char) ch;
 	}
 	result[i] = '\0';
diff -Naur postgresql-8.0.0rc5/src/backend/utils/misc/guc.c postgresql-8.0.0rc5-new/src/backend/utils/misc/guc.c
--- postgresql-8.0.0rc5/src/backend/utils/misc/guc.c	Sat Jan  1 00:43:08 2005
+++ postgresql-8.0.0rc5-new/src/backend/utils/misc/guc.c	Fri Jan 14 13:43:35 2005
@@ -44,6 +44,7 @@
 #include "optimizer/prep.h"
 #include "parser/parse_expr.h"
 #include "parser/parse_relation.h"
+#include "parser/scansup.h"
 #include "postmaster/bgwriter.h"
 #include "postmaster/syslogger.h"
 #include "postmaster/postmaster.h"
@@ -849,6 +850,15 @@
 #else
 		false, NULL, NULL
 #endif
+	},
+	{
+		{"parser_ignore_case", PGC_USERSET, CUSTOM_OPTIONS,
+			gettext_noop("Ignore case of unquoted identifiers"),
+			NULL,
+			GUC_NOT_IN_SAMPLE
+		},
+		&parser_ignore_case,
+		true, NULL, NULL
 	},
 
 	/* End-of-list marker */
diff -Naur postgresql-8.0.0rc5/src/bin/psql/tab-complete.c postgresql-8.0.0rc5-new/src/bin/psql/tab-complete.c
--- postgresql-8.0.0rc5/src/bin/psql/tab-complete.c	Sat Jan  1 00:43:08 2005
+++ postgresql-8.0.0rc5-new/src/bin/psql/tab-complete.c	Fri Jan 14 13:38:52 2005
@@ -575,6 +575,7 @@
 		"max_locks_per_transaction",
 		"max_stack_depth",
 		"password_encryption",
+		"parser_ignore_case",
 		"port",
 		"random_page_cost",
 		"regex_flavor",
diff -Naur postgresql-8.0.0rc5/src/include/parser/scansup.h postgresql-8.0.0rc5-new/src/include/parser/scansup.h
--- postgresql-8.0.0rc5/src/include/parser/scansup.h	Fri Dec 31 17:03:38 2004
+++ postgresql-8.0.0rc5-new/src/include/parser/scansup.h	Fri Jan 14 13:32:07 2005
@@ -15,6 +15,8 @@
 #ifndef SCANSUP_H
 #define SCANSUP_H
 
+extern bool parser_ignore_case;
+
 extern char *scanstr(const char *s);
 
 extern char *downcase_truncate_identifier(const char *ident, int len,
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to