Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

passing external date variable to a query python

desired_date = "2022-09-28" #@param {type:"date"}
import pandas as pd

df = pd.io.gbq.read_gbq('''
  SELECT *
  FROM `gdelt-bq.gdeltv2.geg_gcnlapi`
  WHERE DATE(date) = desired_date
  LIMIT 1000
''', project_id=project_id, dialect='standard')

Trying to pass desired_date to the SQL query, but everything I seem to do results in the following error:
Reason: 400 No matching signature for operator = for argument types: DATE, INT64. Supported signature: ANY = ANY at [4:9]

Thank you for the assistance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You must set the value of the variable in the query, not the variable name.
For eg.,

df = pd.io.gbq.read_gbq(f'''
  SELECT *
  FROM `gdelt-bq.gdeltv2.geg_gcnlapi`
  WHERE DATE(date) = "{desired_date}"
  LIMIT 1000
''', project_id=project_id, dialect='standard')

Just using = desired_date passes the query as with date as ‘desired_date’ and not its value!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading