Issue
From my python code i had the method:
def start_db(event, context):
conn = db()
cur = conn.cursor()
datada = event['data_start']
dataa = event['data_stop']
if not datada or not dataa:
dataa = str(datetime.datetime.now())
datada = str(dataa - datetime.timedelta(days=7))
s_query = "SELECT * FROM a_usage WHERE (bk_tenant = '%s', data_start LIKE '%s'::timestamp, data_stop LIKE '%s'::timestamp);" % (event['bk_tenant'], datada, dataa)
cur.execute(s_query)
A = cur.fetchone()
conn.commit()
cur.close()
conn.close()
return A
but when i run my code (db is postgreSQL) an error occur:
operator does not exist: timestamp without time zone ~~ timestamp without time zone
what's wrong in my code?
Thanks in advance
Solution
It is not clear why you are trying to use LIKE
on timestamps but this cannot work as the operator needs textual arguments.
You can use equality operator on timestamps:
WHERE
bk_tenant = '%s'
AND data_start = '%s'::timestamp
AND data_stop = '%s'::timestamp
or LIKE
on texts:
WHERE
bk_tenant = '%s'
AND data_start::text LIKE '%s'
AND data_stop::text LIKE '%s'
Note also that you should use Boolean operators AND
instead of commas.
Answered By - klin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.