2

I'm trying to write a query which fetches the current date and gets the relevant log data. Have written a nested query which works from PL/SQL but it isn't working from Python environment. Please advise.

Working query for PL/SQL:

SELECT * FROM TBLIRISVISITLOGS TLOG
WHERE TLOG.IVL_VISITDATE = (SELECT TO_CHAR(SYSTIMESTAMP,'DD-MON-YYYY') FROM DUAL)

When I execute this query in Python environment, it fetches an empty table.

2
  • 1
    Why don't you simply use WHERE TLOG.IVL_VISITDATE = CURRENT_DATE? Commented Apr 10, 2019 at 16:28
  • Because this script will run on a daily basis, I need to get current date for that day only. Commented Apr 10, 2019 at 17:36

1 Answer 1

1

seems like I've found the solution:

from pandas import Timestamp as tstamp
test_query = """
SELECT * FROM TBLIRISVISITLOGS T WHERE T.IVL_LATITUDE>0 AND T.IVL_VISITDATE = TO_DATE('{CURR_DATE}','YYYY-MM-DD')
""".format(CURR_DATE=str(tstamp.now().date()))
Sign up to request clarification or add additional context in comments.

4 Comments

Same comment: Why don't you simply use WHERE TLOG.IVL_VISITDATE = CURRENT_DATE?
Because it is part of an automated script that will run periodically every day, it will get data for only that day.
CURRENT_DATE is Standard SQL's a placeholder for today's date, it's the same as tstamp.now().date().
Oh. I didn't know, I'll try this and let you know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.