Teradata不接受熊猫日期变量



我在panda中有一个日期变量,我想通过Teradata sql查询-传递它

import numpy as np
import pyodbc
import time
import os
import teradata as td
from teradata import tdodbc
#create parameters for date
date_from_1 = pd.to_datetime('2021-09-29').strftime('%Y-%m-%d')
date_to_1 = pd.to_datetime('2021-10-30').strftime('%Y-%m-%d')
#sql query
tran = '''SELECT TRAN.ACCOUNT_NUMBER,
TRAN.DATE
from TRANSACTION TABLE TRAN
where TRAN.DATE >= ?
AND TRAN.DATE < ?
'''
pd.read_sql_query(tran, tdp_conn, params = [date_from_1, date_to_1])

':('22008','[222008][Teradata][ODBC Teradata Driver][Teradata Database]提供的日期无效

谢谢!

仅供将来遇到这种情况的每个人参考,解决方案实际上非常简单。

tran = """SELECT top 10 TRAN.ACCOUNT_BSB,
TRAN.ACCOUNT_NUMBER,
TRAN.PROCESS_DATE
from TRANSACTION_TABLE TRAN
where TRAN.PROCESS_DATE >= cast(? as date format 'YYYY-MM-DD')
AND TRAN.PROCESS_DATE < cast(? as date format 'YYYY-MM-DD')
pd.read_sql_query(tran, session, params= [str(date_from),str(date_to)])

相关内容

  • 没有找到相关文章

最新更新