Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asyncpg.exceptions.DataError: invalid input for query argument

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!

like image 576
SmokyICE Avatar asked Jun 26 '26 14:06

SmokyICE


1 Answers

Just replace datetime.now().strftime('%Y-%m-%d') with datetime.date.today().

You need to pass datetime.date object instead of string.

like image 154
Yurii Kramarenko Avatar answered Jul 01 '26 00:07

Yurii Kramarenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!