diff options
Diffstat (limited to 'django/db/backends/postgresql')
-rw-r--r-- | django/db/backends/postgresql/creation.py | 2 | ||||
-rw-r--r-- | django/db/backends/postgresql/operations.py | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py index e3587f0e37..9984716389 100644 --- a/django/db/backends/postgresql/creation.py +++ b/django/db/backends/postgresql/creation.py @@ -64,7 +64,7 @@ class DatabaseCreation(BaseDatabaseCreation): # a second index that specifies their operator class, which is # needed when performing correct LIKE queries outside the # C locale. See #12234. - db_type = f.db_type() + db_type = f.db_type(connection=self.connection) if db_type.startswith('varchar'): output.append(get_index_sql('%s_%s_like' % (db_table, f.column), ' varchar_pattern_ops')) diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index e5dd0fdd11..d55aae93bc 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -55,7 +55,8 @@ class DatabaseOperations(BaseDatabaseOperations): 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): @@ -97,7 +98,7 @@ class DatabaseOperations(BaseDatabaseOperations): 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 @@ -119,7 +120,7 @@ class DatabaseOperations(BaseDatabaseOperations): if isinstance(f, models.BaseAutoField): 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(qn(model._meta.db_table)), style.SQL_FIELD(f.column), style.SQL_FIELD(qn(f.column)), style.SQL_FIELD(qn(f.column)), @@ -131,7 +132,7 @@ class DatabaseOperations(BaseDatabaseOperations): 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(qn(f.m2m_db_table())), style.SQL_FIELD('id'), style.SQL_FIELD(qn('id')), style.SQL_FIELD(qn('id')), |