Index: django/db/backends/postgresql/operations.py
===================================================================
--- django/db/backends/postgresql/operations.py	(revision 13402)
+++ django/db/backends/postgresql/operations.py	(working copy)
@@ -56,7 +56,8 @@
     def last_insert_id(self, cursor, table_name, pk_name):
         # Use pg_get_serial_sequence to get the underlying sequence name
         # from the table name and column name (available since PostgreSQL 8)
-        cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (table_name, pk_name))
+        cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (
+                self.quote_name(table_name), pk_name))
         return cursor.fetchone()[0]
 
     def no_limit_value(self):
@@ -98,7 +99,7 @@
                     column_name = 'id'
                 sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % \
                     (style.SQL_KEYWORD('SELECT'),
-                    style.SQL_TABLE(table_name),
+                    style.SQL_TABLE(self.quote_name(table_name)),
                     style.SQL_FIELD(column_name))
                 )
             return sql
@@ -120,7 +121,7 @@
                 if isinstance(f, models.AutoField):
                     output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
                         (style.SQL_KEYWORD('SELECT'),
-                        style.SQL_TABLE(model._meta.db_table),
+                        style.SQL_TABLE(self.quote_name(model._meta.db_table)),
                         style.SQL_FIELD(f.column),
                         style.SQL_FIELD(qn(f.column)),
                         style.SQL_FIELD(qn(f.column)),
@@ -132,7 +133,7 @@
                 if not f.rel.through:
                     output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
                         (style.SQL_KEYWORD('SELECT'),
-                        style.SQL_TABLE(model._meta.db_table),
+                        style.SQL_TABLE(self.quote_name(model._meta.db_table)),
                         style.SQL_FIELD('id'),
                         style.SQL_FIELD(qn('id')),
                         style.SQL_FIELD(qn('id')),
Index: tests/regressiontests/Bug13832/__init__.py
===================================================================
--- tests/regressiontests/Bug13832/__init__.py	(revision 0)
+++ tests/regressiontests/Bug13832/__init__.py	(revision 0)
@@ -0,0 +1 @@
+
Index: tests/regressiontests/Bug13832/tests.py
===================================================================
--- tests/regressiontests/Bug13832/tests.py	(revision 0)
+++ tests/regressiontests/Bug13832/tests.py	(revision 0)
@@ -0,0 +1,10 @@
+from django.test import TestCase
+from regressiontests.Bug13832 import models
+
+class TestUppercaseAppNames(TestCase):
+    """ Ensure app labels with uppercase characters don't cause DatabaseErrors.
+    
+    (As they did after changeset #13363, when using PostgreSQL).
+    """
+    def test_uppercase(self):
+        models.AppNameTestClass.objects.create()
Index: tests/regressiontests/Bug13832/models.py
===================================================================
--- tests/regressiontests/Bug13832/models.py	(revision 0)
+++ tests/regressiontests/Bug13832/models.py	(revision 0)
@@ -0,0 +1,5 @@
+from django.db import models
+
+class AppNameTestClass(models.Model):
+    token_field = models.CharField(max_length=255)
+  
