summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-25 18:56:43 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-25 18:56:43 +0000
commit861b28f37e790e13dfae45da5042588f0ab57b1a (patch)
tree6f8528c43934589b116751de2d89e2987880e1a9 /django/db/backends/postgresql/operations.py
parentf8e26f5c2c9d263bf7b420abeb50164d6a76a760 (diff)
downloaddjango-861b28f37e790e13dfae45da5042588f0ab57b1a.tar.gz
Fixed #5055 -- Changed Postgres DatabaseOperations.sql_flush() to use 'SELECT setval()' instead of 'ALTER SEQUENCE', because the latter only works with Postgres 7.3+. Thanks, Don Arbow
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6009 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py28
1 files changed, 7 insertions, 21 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 21c017038f..4c32c4eeb1 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -52,28 +52,14 @@ class DatabaseOperations(BaseDatabaseOperations):
for sequence_info in sequences:
table_name = sequence_info['table']
column_name = sequence_info['column']
- if column_name and len(column_name)>0:
- # sequence name in this case will be <table>_<column>_seq
- sql.append("%s %s %s %s %s %s;" % \
- (style.SQL_KEYWORD('ALTER'),
- style.SQL_KEYWORD('SEQUENCE'),
- style.SQL_FIELD(self.quote_name('%s_%s_seq' % (table_name, column_name))),
- style.SQL_KEYWORD('RESTART'),
- style.SQL_KEYWORD('WITH'),
- style.SQL_FIELD('1')
- )
- )
+ if column_name and len(column_name) > 0:
+ sequence_name = '%s_%s_seq' % (table_name, column_name)
else:
- # sequence name in this case will be <table>_id_seq
- sql.append("%s %s %s %s %s %s;" % \
- (style.SQL_KEYWORD('ALTER'),
- style.SQL_KEYWORD('SEQUENCE'),
- style.SQL_FIELD(self.quote_name('%s_id_seq' % table_name)),
- style.SQL_KEYWORD('RESTART'),
- style.SQL_KEYWORD('WITH'),
- style.SQL_FIELD('1')
- )
- )
+ sequence_name = '%s_id_seq' % table_name
+ sql.append("%s setval('%s', 1, false);" % \
+ (style.SQL_KEYWORD('SELECT'),
+ style.SQL_FIELD(self.quote_name(sequence_name)))
+ )
return sql
else:
return []