diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-20 12:49:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-20 12:49:28 -0400 |
| commit | 90335a89a98df23db7a3ae1233eb4fbb5743d2e8 (patch) | |
| tree | 9a4ac236f83696709bd355dcac22552aeb177694 /lib/sqlalchemy/dialects/postgresql/base.py | |
| parent | 75c78aa714ca55818f0ba12a67cf2f77927b68f7 (diff) | |
| download | sqlalchemy-90335a89a98df23db7a3ae1233eb4fbb5743d2e8.tar.gz | |
- Added new generic function "next_value()", accepts
a Sequence object as its argument and renders the
appropriate "next value" generation string on the
target platform, if supported. Also provides
".next_value()" method on Sequence itself.
[ticket:2085]
- added tests for all the conditions described
in [ticket:2085]
- postgresql dialect will exec/compile a Sequence
that has "optional=True". the optional flag is now only
checked specifically in the context of a Table primary key
evaulation.
- func.next_value() or other SQL expression can
be embedded directly into an insert() construct,
and if implicit or explicit "returning" is used
in conjunction with a primary key column,
the newly generated value will be present in
result.inserted_primary_key. [ticket:2084]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 8bceeef65..cc2f461f9 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -461,10 +461,7 @@ class PGCompiler(compiler.SQLCompiler): return value def visit_sequence(self, seq): - if seq.optional: - return None - else: - return "nextval('%s')" % self.preparer.format_sequence(seq) + return "nextval('%s')" % self.preparer.format_sequence(seq) def limit_clause(self, select): text = "" @@ -717,23 +714,19 @@ class DropEnumType(schema._CreateDropBase): class PGExecutionContext(default.DefaultExecutionContext): def fire_sequence(self, seq, type_): - if not seq.optional: - return self._execute_scalar(("select nextval('%s')" % \ - self.dialect.identifier_preparer.format_sequence(seq)), type_) - else: - return None + return self._execute_scalar(("select nextval('%s')" % \ + self.dialect.identifier_preparer.format_sequence(seq)), type_) def get_insert_default(self, column): 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): + if column.server_default and column.server_default.has_argument: # pre-execute passive defaults on primary key columns return self._execute_scalar("select %s" % - column.server_default.arg, column.type) + column.server_default.arg, column.type) elif (column.default is None or - (isinstance(column.default, schema.Sequence) and + (column.default.is_sequence and column.default.optional)): # execute the sequence associated with a SERIAL primary |
