Index: trac/db/postgres_backend.py
===================================================================
--- trac/db/postgres_backend.py	(Revision 7501)
+++ trac/db/postgres_backend.py	(Arbeitskopie)
@@ -66,7 +66,7 @@
         cursor = cnx.cursor()
         if cnx.schema:
             cursor.execute('CREATE SCHEMA "%s"' % cnx.schema)
-            cursor.execute('SET search_path TO %s', (cnx.schema,))
+            cursor.execute('SET search_path TO "%s"', (cnx.schema,))
         from trac.db_default import schema
         for table in schema:
             for stmt in self.to_sql(table):
@@ -74,23 +74,23 @@
         cnx.commit()
 
     def to_sql(self, table):
-        sql = ["CREATE TABLE %s (" % table.name]
+        sql = ['CREATE TABLE "%s" (' % table.name]
         coldefs = []
         for column in table.columns:
             ctype = column.type
             if column.auto_increment:
-                ctype = "SERIAL"
+                ctype = 'SERIAL'
             if len(table.key) == 1 and column.name in table.key:
-                ctype += " PRIMARY KEY"
-            coldefs.append("    %s %s" % (column.name, ctype))
+                ctype += ' PRIMARY KEY'
+            coldefs.append('    "%s" %s' % (column.name, ctype))
         if len(table.key) > 1:
-            coldefs.append("    CONSTRAINT %s_pk PRIMARY KEY (%s)"
-                           % (table.name, ','.join(table.key)))
+            coldefs.append('    CONSTRAINT "%s_pk" PRIMARY KEY ("%s")'
+                           % (table.name, '","'.join(table.key)))
         sql.append(',\n'.join(coldefs) + '\n)')
         yield '\n'.join(sql)
         for index in table.indices:
             unique = index.unique and 'UNIQUE' or ''
-            yield "CREATE %s INDEX %s_%s_idx ON %s (%s)" % (unique, table.name, 
+            yield 'CREATE "%s" INDEX "%s_%s_idx" ON "%s" ("%s")' % (unique, table.name, 
                    '_'.join(index.columns), table.name, ','.join(index.columns))
 
 
@@ -159,7 +159,7 @@
     def like(self):
         # Temporary hack needed for the case-insensitive string matching in the
         # search module
-        return "ILIKE %s ESCAPE '/'"
+        return "ILIKE \"%s\" ESCAPE '/'"
 
     def like_escape(self, text):
         return _like_escape_re.sub(r'/\1', text)

