I'm trying to pass a condition to a query and I'm using PostgreSQLHook in apache airflow. When I run the dag I'm getting an error
TypeError: Object of type 'datetime' is not JSON serializable
Currently I have my sql stored in a different file and I'm importing the file for execution in my python file.
sql pg_query file
SELECT
*
FROM
public.airtimes
WHERE created_at > '{}';
python script
def read_latest_data_from_pg(**kwargs):
with open('dags/scripts/sql_scripts/pg_query.sql','r') as sqlfile:
pg_export_data_query=str(sqlfile.read())
pg_date = '2021-05-01'
pg_hook = PostgresHook(postgres_conn_id='pg_conn', delegate_to=None, use_legacy_sql=False)
conn = pg_hook.get_conn()
cursor = conn.cursor()
cursor.execute(pg_export_data_query.format(pg_date))
result = cursor.fetchall()
print('result', result)
return result
What I'm I missing?