summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-02-11 20:50:41 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-02-11 20:50:41 +0000
commit280274812261868e8f665f706cd27e06eaff4302 (patch)
treee39e17c4a18469c7f47e5a83b19e5f63eaa7b548 /lib/sqlalchemy/databases/postgres.py
parent349c00c97a1931cb28cb199b12af1bde82f5bd1d (diff)
downloadsqlalchemy-280274812261868e8f665f706cd27e06eaff4302.tar.gz
streamlined engine.schemagenerator and engine.schemadropper methodology
added support for creating PassiveDefault (i.e. regular DEFAULT) on table columns postgres can reflect default values via information_schema added unittests for PassiveDefault values getting created, inserted, coming back in result sets
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 9122c2afa..5d0a4e172 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -192,11 +192,11 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
def compiler(self, statement, bindparams, **kwargs):
return PGCompiler(self, statement, bindparams, **kwargs)
- def schemagenerator(self, proxy, **params):
- return PGSchemaGenerator(proxy, **params)
+ def schemagenerator(self, **params):
+ return PGSchemaGenerator(self, **params)
- def schemadropper(self, proxy, **params):
- return PGSchemaDropper(proxy, **params)
+ def schemadropper(self, **params):
+ return PGSchemaDropper(self, **params)
def defaultrunner(self, proxy):
return PGDefaultRunner(self, proxy)
@@ -254,6 +254,12 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
class PGCompiler(ansisql.ANSICompiler):
+ def visit_function(self, func):
+ if len(func.clauses):
+ super(PGCompiler, self).visit_function(func)
+ else:
+ self.strings[func] = func.name
+
def visit_insert_column(self, column):
# Postgres advises against OID usage and turns it off in 8.1,
# effectively making cursor.lastrowid
@@ -273,14 +279,16 @@ class PGCompiler(ansisql.ANSICompiler):
return text
class PGSchemaGenerator(ansisql.ANSISchemaGenerator):
+
def get_column_specification(self, column, override_pk=False, **kwargs):
colspec = column.name
- if isinstance(column.default, schema.PassiveDefault):
- colspec += " DEFAULT " + column.default.text
- elif column.primary_key and isinstance(column.type, types.Integer) and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)):
+ if column.primary_key and isinstance(column.type, types.Integer) and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)):
colspec += " SERIAL"
else:
colspec += " " + column.type.get_col_spec()
+ default = self.get_column_default_string(column)
+ if default is not None:
+ colspec += " DEFAULT " + default
if not column.nullable:
colspec += " NOT NULL"