always update dates table (#35725)

This commit is contained in:
Frédéric Péters 2019-09-01 09:48:46 +02:00
parent b5ceb76525
commit a5168d1f15
1 changed files with 6 additions and 7 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
import six
import copy
import itertools
@ -331,18 +332,16 @@ class WcsOlapFeeder(object):
self.ex('DROP TABLE IF EXISTS %s CASCADE;' % tablename)
def do_dates_table(self):
# test if public.dates exists
self.ex("SELECT * FROM information_schema.tables WHERE table_name = 'dates' AND"
" table_schema = 'public'")
if len(list(self.cur.fetchall())) < 1:
self.ex('''
self.ex("DROP TABLE IF EXISTS public.dates")
last_date = datetime.datetime.today().replace(month=12, day=31)
self.ex('''
CREATE TABLE public.dates AS (SELECT
the_date.the_date::date AS date,
to_char(the_date.the_date, 'TMday') AS day,
to_char(the_date.the_date, 'TMmonth') AS month
FROM
generate_series('2010-01-01'::date, '2020-01-01'::date, '1 day'::interval)
AS the_date(the_date));''')
generate_series('2010-01-01'::date, '%s'::date, '1 day'::interval)
AS the_date(the_date));''' % last_date.strftime('%Y-%m-%d'))
def create_table(self, name, columns, inherits=None, comment=None):
sql = 'CREATE TABLE "%s"' % name