Skip to content

Commit

Permalink
convert postgresql date_trunc() to UTC to prevent pandas error (#4319)
Browse files Browse the repository at this point in the history
* cast postgresql date_trunc() to timestamp without time zone to prevent pandas error

* fix formatting for flake8

* change cast to timezone conversion instead
  • Loading branch information
habalux authored and mistercrunch committed Feb 7, 2018
1 parent d5ab6c8 commit 3b35ddf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b35ddf

Please sign in to comment.