I asyncpg use library for connect to mydb through pool. To execute this code block i get a mistake: asyncpg.exception.Data Error: invalid input for query argument $10: '2019-12-31' ('str' object has no attribute 'toordinal')
My code:
await db.execute("""
insert into hs.public.users
(u_login,.....,u_reg_date)
values
($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
""", data ['email'].split('@')[0],....., datetime.now().strftime('%Y-%m-%d'))
In my DB, the "u_reg_date" field is of type "date". If you use the {} sign instead of $, then everything works. I would like to know why and what I do wrong, although judging by the documentation I do everything correctly. Thanks. Happy new year and Christmas!
Just replace datetime.now().strftime('%Y-%m-%d') with datetime.date.today().
You need to pass datetime.date object instead of string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With