diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-15 16:42:29 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-15 16:42:29 -0500 |
| commit | dff5a404e489d5215da5aa30870b78aca8423de5 (patch) | |
| tree | 39f6ae1949762d269f6a73e0315f0fa6910ceacd /lib/sqlalchemy/dialects/postgresql/base.py | |
| parent | fc0ffac24155931c2db10d1a469e1f7898268e45 (diff) | |
| download | sqlalchemy-dff5a404e489d5215da5aa30870b78aca8423de5.tar.gz | |
- getting slightly more consistent behavior for the edge case of pk columns
with server default - autoincrement is now false with any server_default,
so these all return None, applies consistency to [ticket:2020], [ticket:2021].
if prefetch is desired a "default" should be used instead of server_default.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 7c712e8aa..a8fb4e51a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -508,13 +508,15 @@ class PGDDLCompiler(compiler.DDLCompiler): colspec = self.preparer.format_column(column) type_affinity = column.type._type_affinity if column.primary_key and \ - len(column.foreign_keys)==0 and \ - column.autoincrement and \ - issubclass(type_affinity, sqltypes.Integer) and \ + column is column.table._autoincrement_column and \ not issubclass(type_affinity, sqltypes.SmallInteger) and \ - (column.default is None or - (isinstance(column.default, schema.Sequence) and - column.default.optional)): + ( + column.default is None or + ( + isinstance(column.default, schema.Sequence) and + column.default.optional + ) + ): if issubclass(type_affinity, sqltypes.BigInteger): colspec += " BIGSERIAL" else: @@ -689,7 +691,7 @@ class PGExecutionContext(default.DefaultExecutionContext): return None def get_insert_default(self, column): - if column.primary_key: + if column.primary_key and column is column.table._autoincrement_column: if (isinstance(column.server_default, schema.DefaultClause) and column.server_default.arg is not None): @@ -697,8 +699,7 @@ class PGExecutionContext(default.DefaultExecutionContext): return self._execute_scalar("select %s" % column.server_default.arg, column.type) - elif column is column.table._autoincrement_column \ - and (column.default is None or + elif (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)): |
