summaryrefslogtreecommitdiff
path: root/test/dialect/test_postgresql.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r--test/dialect/test_postgresql.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 152ca40da..2a2322441 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -104,9 +104,15 @@ class CompileTest(TestBase, AssertsCompiledSQL):
for field in 'year', 'month', 'day':
self.assert_compile(
select([extract(field, t.c.col1)]),
- "SELECT EXTRACT(%s FROM t.col1::timestamp) AS anon_1 "
+ "SELECT EXTRACT(%s FROM t.col1 :: timestamp) AS anon_1 "
"FROM t" % field)
+ for field in 'year', 'month', 'day':
+ self.assert_compile(
+ select([extract(field, func.timestamp() - datetime.timedelta(days =5))]),
+ "SELECT EXTRACT(%s FROM (timestamp() - %%(timestamp_1)s) :: timestamp) AS anon_1"
+ % field)
+
class FloatCoercionTest(TablesTest, AssertsExecutionResults):
__only_on__ = 'postgresql'
__dialect__ = postgresql.dialect()
@@ -938,6 +944,19 @@ class MiscTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
finally:
meta1.drop_all()
+ def test_extract(self):
+ fivedaysago = datetime.datetime.now() - datetime.timedelta(days=5)
+ for field, exp in (
+ ('year', fivedaysago.year),
+ ('month', fivedaysago.month),
+ ('day', fivedaysago.day),
+ ):
+ r = testing.db.execute(
+ select([extract(field, func.now() + datetime.timedelta(days =-5))])
+ ).scalar()
+ eq_(r, exp)
+
+
def test_checksfor_sequence(self):
meta1 = MetaData(testing.db)
t = Table('mytable', meta1,