convert postgresql date_trunc() to UTC to prevent pandas error (#4319)

* cast postgresql date_trunc() to timestamp without time zone to prevent pandas error

* fix formatting for flake8

* change cast to timezone conversion instead
This commit is contained in:
Teemu Haapoja 2018-02-07 18:18:11 +02:00 committed by Maxime Beauchemin
parent d5ab6c8d3d
commit 3b35ddf135
1 changed files with 16 additions and 8 deletions

View File

@ -288,14 +288,22 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
time_grains = (
Grain('Time Column', _('Time Column'), '{col}'),
Grain('second', _('second'), "DATE_TRUNC('second', {col})"),
Grain('minute', _('minute'), "DATE_TRUNC('minute', {col})"),
Grain('hour', _('hour'), "DATE_TRUNC('hour', {col})"),
Grain('day', _('day'), "DATE_TRUNC('day', {col})"),
Grain('week', _('week'), "DATE_TRUNC('week', {col})"),
Grain('month', _('month'), "DATE_TRUNC('month', {col})"),
Grain('quarter', _('quarter'), "DATE_TRUNC('quarter', {col})"),
Grain('year', _('year'), "DATE_TRUNC('year', {col})"),
Grain('second', _('second'),
"DATE_TRUNC('second', {col}) AT TIME ZONE 'UTC'"),
Grain('minute', _('minute'),
"DATE_TRUNC('minute', {col}) AT TIME ZONE 'UTC'"),
Grain('hour', _('hour'),
"DATE_TRUNC('hour', {col}) AT TIME ZONE 'UTC'"),
Grain('day', _('day'),
"DATE_TRUNC('day', {col}) AT TIME ZONE 'UTC'"),
Grain('week', _('week'),
"DATE_TRUNC('week', {col}) AT TIME ZONE 'UTC'"),
Grain('month', _('month'),
"DATE_TRUNC('month', {col}) AT TIME ZONE 'UTC'"),
Grain('quarter', _('quarter'),
"DATE_TRUNC('quarter', {col}) AT TIME ZONE 'UTC'"),
Grain('year', _('year'),
"DATE_TRUNC('year', {col}) AT TIME ZONE 'UTC'"),
)
@classmethod