]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed pg reflection of timezones
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Oct 2006 20:49:16 +0000 (20:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Oct 2006 20:49:16 +0000 (20:49 +0000)
lib/sqlalchemy/databases/postgres.py
test/engine/reflection.py

index dad2d3bff2d9b1a710fc3e161571b770b2b20d62..93a2cf8643d0669dc4bde17a2ad58dea19b42c07 100644 (file)
@@ -359,14 +359,20 @@ class PGDialect(ansisql.ANSIDialect):
                 if attype == 'integer':
                     numericprec, numericscale = (32, 0)
                     charlen = None
-    
+
                 args = []
                 for a in (charlen, numericprec, numericscale):
                     if a is not None:
                         args.append(int(a))
+
+                kwargs = {}
+                if attype == 'timestamp with time zone':
+                    kwargs['timezone'] = True
+                elif attype == 'timestamp without time zone':
+                    kwargs['timezone'] = False
     
                 coltype = ischema_names[attype]
-                coltype = coltype(*args)
+                coltype = coltype(*args, **kwargs)
                 colargs= []
                 if default is not None:
                     colargs.append(PassiveDefault(sql.text(default)))
index fa0cb4245aec4abb65594844c009106ebb78ee0a..6c367159b41c74c8bedd514f2ffad22073415871 100644 (file)
@@ -97,7 +97,24 @@ class ReflectionTest(PersistTest):
         finally:
             addresses.drop()
             users.drop()
-    
+            
+    @testbase.supported('postgres')
+    def testpgdates(self):
+        m1 = BoundMetaData(testbase.db)
+        t1 = Table('pgdate', m1, 
+            Column('date1', DateTime(timezone=True)),
+            Column('date2', DateTime(timezone=False))
+            )
+        m1.create_all()
+        try:
+            m2 = BoundMetaData(testbase.db)
+            t2 = Table('pgdate', m2, autoload=True)
+            assert t2.c.date1.type.timezone is True
+            assert t2.c.date2.type.timezone is False
+        finally:
+            m1.drop_all()
+            
+            
     def testoverridecolumns(self):
         """test that you can override columns which contain foreign keys to other reflected tables"""
         meta = BoundMetaData(testbase.db)