def db_connect():
#Please assign variables in dict db = {"database":"", ...}
try:
conn = psycopg2.connect(database=db["database"], user=db["user"], password=db["password"], host=db["host"], port=db.get("port", "5432"))
except:
conn = None
print "I am unable to connect to the database"
return conn
def db_query_time():
conn = db_connect()
if conn is not None:
cur = conn.cursor()
query_generate_date_series = '''SELECT to_char(day, 'YYYYMMDD') as day_f FROM generate_series( '2017-10-23'::timestamp,'2017-10-29'::timestamp, '1 day'::interval) day ;'''
cur.execute(query_generate_date_series)
rows = cur.fetchall()
print rows
Output looks like this: [('20171023',), ('20171024',), ('20171025',), ('20171026',), ('20171027',), ('20171028',), ('20171029',)]
I want dates to be in a list format. and I don't like how we are returning tuple and 2 commas instead of 1 comma. Can anyone please explain me what is the reason behind and how to fix this?
Note: Need postgres DB to run this.