From 0d1f27dbc1a622fb0e40cb0fa872340349477d03 Mon Sep 17 00:00:00 2001 From: andrewhn Date: Tue, 5 Apr 2016 13:56:10 +1000 Subject: [PATCH] add postgres grains --- caravel/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/caravel/models.py b/caravel/models.py index c6c0e65aa..8bcfb6cce 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -337,6 +337,14 @@ class Database(Model, AuditMixinNullable): Grain('week', 'DATE_SUB({col}, INTERVAL DAYOFWEEK({col}) - 1 DAY)'), Grain('month', 'DATE_SUB({col}, INTERVAL DAYOFMONTH({col}) - 1 DAY)'), ), + 'postgresql': ( + Grain("Time Column", "{col}"), + Grain("hour", "DATE_TRUNC('hour', {col})"), + Grain("day", "DATE_TRUNC('day', {col})"), + Grain("week", "DATE_TRUNC('week', {col})"), + Grain("month", "DATE_TRUNC('month', {col})"), + Grain("year", "DATE_TRUNC('year', {col})"), + ), } for db_type, grains in db_time_grains.items(): if self.sqlalchemy_uri.startswith(db_type):