summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-01-11 15:22:46 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-01-11 15:22:46 -0500
commit67e0f356b2093fdc03303d50be1f89e75e847c7f (patch)
treee2209edb3a8aeb16702bc47573b9809a8e521db5 /lib/sqlalchemy/dialects/postgresql
parent0342a4886f00b34cf02e0d2d986a0896ba946788 (diff)
downloadsqlalchemy-67e0f356b2093fdc03303d50be1f89e75e847c7f.tar.gz
- A TypeDecorator of Integer can be used with a primary key
column, and the "autoincrement" feature of various dialects as well as the "sqlite_autoincrement" flag will honor the underlying database type as being Integer-based. [ticket:2005] - Result-row processors are applied to pre-executed SQL defaults, as well as cursor.lastrowid, when determining the contents of result.inserted_primary_key. [ticket:2006] - Bind parameters present in the "columns clause" of a select are now auto-labeled like other "anonymous" clauses, which among other things allows their "type" to be meaningful when the row is fetched, as in result row processors. - TypeDecorator is present in the "sqlalchemy" import space.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 31f699d2b..84fd96edd 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -506,15 +506,16 @@ class PGCompiler(compiler.SQLCompiler):
class PGDDLCompiler(compiler.DDLCompiler):
def get_column_specification(self, column, **kwargs):
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 \
- isinstance(column.type, sqltypes.Integer) and \
- not isinstance(column.type, sqltypes.SmallInteger) and \
+ issubclass(type_affinity, sqltypes.Integer) and \
+ not issubclass(type_affinity, sqltypes.SmallInteger) and \
(column.default is None or
(isinstance(column.default, schema.Sequence) and
column.default.optional)):
- if isinstance(column.type, sqltypes.BigInteger):
+ if issubclass(type_affinity, sqltypes.BigInteger):
colspec += " BIGSERIAL"
else:
colspec += " SERIAL"
@@ -680,21 +681,21 @@ class DropEnumType(schema._CreateDropBase):
__visit_name__ = "drop_enum_type"
class PGExecutionContext(default.DefaultExecutionContext):
- def fire_sequence(self, seq):
+ def fire_sequence(self, seq, proc):
if not seq.optional:
return self._execute_scalar(("select nextval('%s')" % \
- self.dialect.identifier_preparer.format_sequence(seq)))
+ self.dialect.identifier_preparer.format_sequence(seq)), proc)
else:
return None
- def get_insert_default(self, column):
+ def get_insert_default(self, column, proc):
if column.primary_key:
if (isinstance(column.server_default, schema.DefaultClause) and
column.server_default.arg is not None):
# pre-execute passive defaults on primary key columns
return self._execute_scalar("select %s" %
- column.server_default.arg)
+ column.server_default.arg, proc)
elif column is column.table._autoincrement_column \
and (column.default is None or
@@ -713,9 +714,9 @@ class PGExecutionContext(default.DefaultExecutionContext):
exc = "select nextval('\"%s_%s_seq\"')" % \
(column.table.name, column.name)
- return self._execute_scalar(exc)
+ return self._execute_scalar(exc, proc)
- return super(PGExecutionContext, self).get_insert_default(column)
+ return super(PGExecutionContext, self).get_insert_default(column, proc)
class PGDialect(default.DefaultDialect):
name = 'postgresql'