2021年3月6日星期六

Using `GETDATE()` Redshift function with psycopg2 execute_values

Is it possible to use the Redshift function GETDATE() along with psycopg2.extras.execute_values when inserting many rows?

df = pd.DataFrame(data={              'ExampleID' : list(range(1,6)),              'NumericField' : list(range(44,49)),              'UpdateTime' : list('GETDATE()' for i in range(5))              })    conn = psycopg2.connect(dbname=database, host=host, port=5439, user=username, password=password)  cursor = conn.cursor()  v = df.to_records(index=False).tolist()    q = sql.SQL('INSERT INTO tblexample (ExampleID, NumericField, UpdateTime) VALUES %s')  execute_values(cursor, q.as_string(cursor), v)  conn.commit()  

Unfortunately, this raises an exception: psycopg2.DataError: invalid input syntax for type timestamp: "GETDATE()"

https://stackoverflow.com/questions/66513083/using-getdate-redshift-function-with-psycopg2-execute-values March 07, 2021 at 12:04PM

没有评论:

发表评论